简体   繁体   中英

Regular Expression Match to Extract Command

String: Z123xy;Z123od33;Z123od343;Z251od541;
Regex: Z.*?od.*?;
Required Output: [Z123od33; Z123od343; Z251od541;] [Z123od33; Z123od343; Z251od541;]
But Current Output : [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 ; and analyze the parts later separately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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