Regular Expression Match to Extract Command

痴心易碎 提交于 2019-12-12 18:39:32

问题


String: Z123xy;Z123od33;Z123od343;Z251od541;
Regex: Z.*?od.*?;
Required Output: [Z123od33; Z123od343; Z251od541;]
But Current Output : [Z123xy;Z123od33; Z123od343; Z251od541;]

I know why its happening that way but don't know how to solve this. Any one could help please


回答1:


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.



来源:https://stackoverflow.com/questions/40838676/regular-expression-match-to-extract-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!