正则表达式,特定seq

编程入门 行业动态 更新时间:2024-10-24 08:24:15
本文介绍了正则表达式,特定seq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好b $ b 如何匹配以下3组的特定序列。 aB必须在cD和eF之前出现。 cD必须在eF之前。 所有组都可以匹配多次,但是按照指定的顺序。 团体: aB cD eF 匹配: aBcDeF aBcDcDeFeF 不配比赛 cDaBeF 我在尝试: regex =新的正则表达式(@(aB) * \ G(cD)* \(eF)*); 但是它以任何顺序与本集团匹配!

解决方案

当然它以任何顺序匹配组,因为这是你编写正则表达式的方式。这是一个想法:通过在圆括号中按给定顺序包含所有三个组来添加另一个组,并查找该根组的匹配。
- SA

Hi how do i match a specific sequence of the 3 Groups below. aB must come before cD and eF. cD must come before eF. All groups can match more than once, but in the specified order. Groups: aB cD eF Should Match: aBcDeF aBcDcDeFeF Should not Match cDaBeF I was trying: regex = new Regex(@"(aB)*\G(cD)*\G(eF)*"); but it matches the Group in any order !

解决方案

Of course it matches the group in any order, because this is how you wrote your regular expression. Here is the idea: add another group by enclosing all three groups in the given order in round brackets and look for the match of this root group.
—SA

更多推荐

正则表达式,特定seq

本文发布于:2023-11-29 23:20:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647940.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正则表达式   seq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!