简体   繁体   English

正则表达式匹配以提取命令

[英]Regular Expression Match to Extract Command

String: Z123xy;Z123od33;Z123od343;Z251od541; 字符串: Z123xy;Z123od33;Z123od343;Z251od541;
Regex: Z.*?od.*?; 正则表达式: Z.*?od.*?;
Required Output: [Z123od33; Z123od343; Z251od541;] 所需输出: [Z123od33; Z123od343; Z251od541;] [Z123od33; Z123od343; Z251od541;]
But Current Output : [Z123xy;Z123od33; Z123od343; Z251od541;] 但是电流输出: [Z123xy;Z123od33; Z123od343; Z251od541;] [Z123xy;Z123od33; Z123od343; Z251od541;]

在此处输入图片说明

I know why its happening that way but don't know how to solve this. 我知道为什么会这样,但是不知道如何解决。 Any one could help please 任何人都可以帮忙

You could go for 你可以去

Z[^;]*?od[^;]*?;
# require a Z
# anything not a ; lazily
# od
# anything not a ; lazily again
# followed by a ;

See a demo on regex101.com or split on the ; 请参阅regex101.com上的演示,或在上拆分; and analyze the parts later separately. 然后分别分析这些零件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM