我有以下字符串:
bla bla XX_XXX = 999 OR XX _ XXX = 890 OR XX _X XX = 789 OR XX_ XX = 123
我想要检索XX_XXX
和 XX _ XXX
和 XX _X XX
和 {{1 }}
我可以使每个单独工作,但不是一次性在一个正则表达式中。这可能吗?怎么样?
答案 0 :(得分:1)
答案 1 :(得分:0)
我想你想要这样的东西,
(?<=\s|^)[A-Z][A-Z]\s*_(?:\s*[A-Z])+
<强>解释强>
' '
(?<= look behind to see if there is:
\s whitespace (\n, \r, \t, \f, and " ")
| OR
^ the beginning of the string
) end of look-behind
[A-Z] any character of: 'A' to 'Z'
[A-Z] any character of: 'A' to 'Z'
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times)
_ '_'
(?: group, but do not capture (1 or more
times):
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times)
[A-Z] any character of: 'A' to 'Z'
)+ end of grouping
答案 2 :(得分:0)