是否可能匹配最后一个系列和数字从一个字符串看起来像:
CUI: RO39890982 BZ 347
我想要的:BZ
和347
来自两个独立的正则表达式
我在尝试什么:CUI:[ ]*sS*s(.*)
结果:BZ 347
任何帮助都非常感谢!谢谢。
如果你想要两个独立的表达式:
正则表达式1使用(S+)
捕获第1组中的1个或多个非空白字符:
CUI:s*S+s+(S+)
Regex演示
正则表达式2使用限定词{2}
重复非捕获组,并为值
CUI:s*S+(?:s+(S+)){2}
Regex演示
如果您想在更多字段中重用量词,使用量词可能会很方便。
对于显示的示例,请尝试以下正则表达式。
正则表达式1:
获取BZ
值:
bCUI:s+S+s+(S+)
解释: 添加以上regex的详细说明:
bCUI: ##Matching a word boundary with string CUI: here.
s+S+s+ ##Matching 1 or more spaces followed by 1 or more non-spaces, followed by 1 or more spaces here.
(S+) ##Creating 1st capturing group which has 1 or more non-spaces here, which will catch BZ value here.
正则表达式2:获取347
值(或类似模式值)与所示示例。
bCUI:s+S+s+S+s+(S+)
解释:为以上内容添加详细说明。
bCUI: ##Matching a word boundary with string CUI: here.
s+S+s+ ##Matching 1 or more spaces followed by 1 or more non-spaces, followed by 1 or more spaces here.
S+s+ ##matching 1 or non-spaces followed by 1 or more spaces here.
(S+) ##Creating 1st capturing group which has 1 or more non-spaces here, which will catch 347 value here.
正则表达式的在线演示
Get347
with
CUI: *S+ +[A-Z]+ +(d+)
GetBZ
with
CUI: *S+ +([A-Z]+)
正则表达式证明#1,正则表达式证明#2。
--------------------------------------------------------------------------------
CUI: 'CUI:'
--------------------------------------------------------------------------------
* ' ' (0 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
S+ non-whitespace (all but n, r, t, f,
and " ") (1 or more times (matching the
most amount possible))
--------------------------------------------------------------------------------
+ ' ' (1 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
[A-Z]+ any character of: 'A' to 'Z' (1 or more
times (matching the most amount possible))
--------------------------------------------------------------------------------
+ ' ' (1 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
( group and capture to 1:
--------------------------------------------------------------------------------
d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
) end of 1