简化正则表达式 [英] simplifying regular expression

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

问题描述

我正在练习有关正则表达式的练习,我真的不确定如何做到这一点.

I am going through exercises regarding regular expressions, and I am really unsure on how to do this.

正则表达式为:

((a*)(b*))* ∪ (a*)

我真的很不好,但是我认为((a*)(b*))*可以简化为(a ∪ b)*,但是如果这是对的,那么最后一个∪ (a*)实际上只是重复,所以我认为整个表达式可以是简化为(a ∪ b)*.这似乎正确吗?

I am really bad at this, but I think that ((a*)(b*))* can be simplified to (a ∪ b)* But if this is right, than the last ∪ (a*) is really just a repetition, so I figure the whole expression can be simplified to (a ∪ b)*. Does this seem correct?

∪代表联合

推荐答案

您是对的. (a*b*)*可以匹配a和b的任何字符串,(a U b)*也可以匹配,因此它们是等效的. (a U b)*a*相交是a*,因此a*(a U b)*的子集.因此,整个表达式可以简化为(a U b)*.

You are right. (a*b*)* can match any string of a's and b's, so can (a U b)*, therefore they are equivalent. (a U b)* intersect a* is a* so a* is a subset of (a U b)*. Consequently, the whole expression can be simplified to (a U b)*.

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

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