字符串匹配中的正则表达式评估(regular expression evaluation in string matching)

编程入门 行业动态 更新时间:2024-10-25 08:28:18
字符串匹配中的正则表达式评估(regular expression evaluation in string matching)

我正在阅读Robert Sedgwick的Algorithms中的正则表达式。

这里为正则表达提到下面

A* | (A*BA*BA*)*

这里作者提到的匹配是:AAA,BBAABB和BABAAA。 与上述正则表达式不匹配的是ABA BBB BABBAAA。

我的问题是BBAABB如何匹配以及BABAAA如何匹配。 请解释一下。

一般来说,我正在寻找如何评估| 和正则表达式中的*运算符。 在下面的例子中,如果我们有一个+,我们如何才能在b中单独使用b,因为它说我们必须至少有一个a。

(a+b)* = (λ, a, b, aa, ab, ba, bb, aaa, ...)

I am reading Regular expression in Algorithms by Robert Sedgwick book.

Here for regular expression mention below

A* | (A*BA*BA*)*

Here author mentioned matches are: AAA, BBAABB, and BABAAA. does not match for above regular expression are ABA BBB BABBAAA.

My question is how BBAABB is matching and same way how BABAAA is matching. Kindly explain.

In general I am looking for how to evaluate with | and * operators in regular expressions. in below example how we can get b alone in set if we have a+ since it says we must have atleast 1 a.

(a+b)* = (λ, a, b, aa, ab, ba, bb, aaa, ...)

最满意答案

*和+之间有一个区别。 你放*之后的角色可以没有重复。 但在+情况下,它可以有至少1次重复。 在A* | (A*BA*BA*)* A* | (A*BA*BA*)* , BBAABB有以下原因并且符合(A*BA*BA*)*模式

A*开头没有A BA*为1 B而没有A BA*和BA* 1B *在(A*BA*BA*)*显示图案可以重复。 所以第二次重复是BB ,这是有效的

这些是BBAABB有效的点。

There is one difference between * and +. The character after which you put * can have no repetition. But in + case, it can have minimum 1 repetition. In A* | (A*BA*BA*)*, BBAABB is valid for following reasons and it is according to (A*BA*BA*)* pattern

No A at start for A* 1 B for BA* and no A 1 B for BA* and 2 A * at end of (A*BA*BA*)*shows that pattern can repeat. So second repetition is BB which is valid

These are the points for which BBAABB is valid.

更多推荐

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

发布评论

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

>www.elefans.com

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