re
模块捕获单词的所有修饰语
color
在上午。英语(AmE)和Br。英语(BrE)。我成功地捕捉到了几乎所有的单词,除了以撇号结尾的单词。例如。
colors'
以下是示例文本:
Red is a color.
His collar is too tight or too colouuuurful.
These are bright colours.
These are bright colors.
Calorific is a scientific term.
âYour life is very colorful,â she said.
color (U.S. English, singular noun)
colour (British English, singular noun)
colors (U.S. English, plural noun)
colours (British English, plural noun)
colorâs (U.S. English, possessive singular)
colourâs (British English, possessive singular)
colorsâ (U.S. English, possessive plural)
coloursâ (British English, possessive plural)
这是我的正则表达式:
\bcolou?r(?:[a-zA-Zâs]+)?\b
说明:
\b # Start at word boundary
colou?r #u is optional for AmE
(?: #non-capturing group
[a-zA-Zâs]+ #color could be followed by modifier (e.g.ful, or apostrophe)
)? #End non-capturing group; these letters are optional
\b # End at word boundary
问题是
colorsâ
和
coloursâ
匹配到
s
. 撇号被忽略。有人能解释一下我的代码有什么问题吗?我是这么研究的
Regex Apostrophe how to match?
'
和
"
.
Regex101
提前谢谢。