正则表达式匹配以提取命令 [英] Regular Expression Match to Extract Command

查看:222
本文介绍了正则表达式匹配以提取命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

字符串:Z123xy;Z123od33;Z123od343;Z251od541;
正则表达式:Z.*?od.*?;
必需的输出:[Z123od33; Z123od343; Z251od541;]
但是当前输出:[Z123xy;Z123od33; Z123od343; Z251od541;]

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

推荐答案

您可以尝试

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

请参见 regex101.com上的演示 或在;并在以后分别分析各部分.

See a demo on regex101.com or split on the ; and analyze the parts later separately.

这篇关于正则表达式匹配以提取命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆