Angular 中字符串中重复单词的正则表达式,其中一个单词带有撇号
我想为某个要求创建一个正则表达式,一个字符串具有重复的单词,但在该重复的单词中,一个带有撇号。
例如:
EXCHANGE CORRESPONDENCE WITH BOLNO'S COUNSEL RE SCHEDULING INTERVIEW WITH DAVID BOLNO.
我正在使用这个正则表达式通过这种方式进行验证,并用该单词分割字符串。
var splitArray = this.narrative.split(new RegExp("\\b(" + this.misspelledWords[m] + ")\\b"))
但是这个正则表达式字符串将 BOLNO 和 BOLNO'S 视为单个单词。但我想以一种应该将 BOLNO'S 和 BOLNO 视为不同的方式创建我的正则表达式。
谁能帮我这个。
I want to create a regex for a requirement, a string is having duplicate words but in that duplicate words one is with a apostrophe.
For example:
EXCHANGE CORRESPONDENCE WITH BOLNO'S COUNSEL RE SCHEDULING INTERVIEW WITH DAVID BOLNO.
I am using this regex to validate by this way and splitting the string with that word.
var splitArray = this.narrative.split(new RegExp("\\b(" + this.misspelledWords[m] + ")\\b"))
But this regex string is considering BOLNO and BOLNO'S as single word.But I want to create my regex in such a way that it should consider BOLNO'S and BOLNO as different.
Can anyone help me this one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
这也意味着
this.misspelledWords[m]
单词不能包含特殊字符。如果右侧紧接着有
'
或单词字符,则(?!['\w])
负向前视会导致匹配失败。You can use
This also implies the
this.misspelledWords[m]
word cannot contain special chars.The
(?!['\w])
negative lookahead fails the match if there is a'
or a word char immediately on the right.