我只想在类别出现之前匹配":red"、":10"、":[特殊]"(我想在之后使用替换函数消除它们)
category fruit(color: red, size: 10, others: [special])
我有上面的正则表达式
(((:\s*[\w\[\]]+)(?=[,\)]))+)
除了类别,我似乎不能使用lookbehind.
我只想在类别出现之前匹配":red"、":10"、":[特殊]"(我想在之后使用替换函数消除它们)
category fruit(color: red, size: 10, others: [special])
我有上面的正则表达式
(((:\s*[\w\[\]]+)(?=[,\)]))+)
除了类别,我似乎不能使用lookbehind.
如果我们采用以下输入verbatim????:
Figure I - Input String
category fruit(color: red, size: 10, others: [special])
使用正向查找来匹配文字: red
、: 10
和: [special]
:
Figure II
/(?<=category[\S\s]+?)(:\s?red|:\s?10|:\s?\[special\])/g
Figure III
Segment | Description |
---|---|
(?<=category[\S\s]+?) |
Match, but do not consume, literal "categorey", anything in between if it proceeds... |
(:\s?red|:\s?10|:\s?\[special\]) |
...literal colon, zero to one space, literal "read" OR literal colon, zero to one space, literal "10" OR literal colon, zero to one space, literal "[special]" |
参见Regex101
???? Jeffery Flynt comments 说它在语法上不正确,我不得不同意