我需要做一个正则表达式来匹配大文本中的关键字。
大文本的一个例子可以是:
...another语句结尾关键词: tag 1,tag 2,tag 3(可能包含类似这个引用的内容)。1),标签4和标签5.另一句已经开始.
regex必须提取:
关键词:标签1,标签2,标签3(可能包含类似的引用。1)、标签4和标签5
我有以下代码:
\bKeywords:[^\.]+但问题是正则表达式并没有避免括号内的文本,而是以"..ref. 1..“上的点结束。
谢谢大家!
注意:“标签”这个词就是一个例子,它可以是任何一个词。
发布于 2018-08-02 17:36:02
假设parantheses不能嵌套:Keywords: (?:[^(.]|\([^)]*\))*。
我在匹配:
(?:[^(.]|\([^)]*\))*
* as many times as possible
(?: ) non-capturing
| either:
[^(.] a character that's not an opening paranthesis or a dot, or
\( \) inside literal parantheses
[^)]* as many characters that aren't closing parantheses as possible如果可以嵌套parantheses,那么regex并不是您想要的,因为您试图捕获的语言是上下文无关。
https://stackoverflow.com/questions/51658169
复制相似问题