下面的正则表达式相同吗?如果不同分们分别匹配什么?
下面的正则表达式相同吗?如果不同分们分别匹配什么?/^(a|b)*$/
/^a*|b*$/ 'ba' as example:
it match the first one but disagree with the following one.
the secend one means:
/(^a*)|(b*$)/
sorry but no chinese IME;-) sorry for mistake
the word I said above may be correct if U change '*' to '+'
here U use '*'
so let's use 'c' as example:
it dismatch the first RE cause it means: only 'a' or 'b' can exist from the begin of the line to the end.
and it match the secend RE cause the '*' can be zero 能不能用中文?
真的没有人能详细说明上面的两个正则的不同吗?
Re: 下面的正则表达式相同吗?如果不同分们分别匹配什么?
下面的正则表达式相同吗?如果不同分们分别匹配什么?/^(a|b)*$/
^表示行首,$表示行尾,(a|b)表示a或者b匹配其中一个就可以,*表示前面一个char.set出现的次数为0次或多次
/^a*|b*$/
差别应该可以看出来了吧 zhongwen mei you, pingying xing ma?-( 倒~~~~~~~~~~~~~
Re: 下面的正则表达式相同吗?如果不同分们分别匹配什么?
下面的正则表达式相同吗?如果不同分们分别匹配什么?/^(a|b)*$/
^表示行首,$表示行尾,(a|b)表示a或者b匹配其中一个就可以,*表示前面一个char.set出现的次数为0次或多次
/^a*|b*$/
差别应该可以看出来了吧
这个我知道,可是很奇怪的是用/^a*|b*$/匹配任何字符串,可是匹配长度为0(当然字符串中不含a和b)但是他却有返回True,说有找到!我真晕了 *本来就是0个或者多个啊 *本来就是0个或者多个啊
你但是匹配的是0个或是多个a或是b, 比如我输入一个214123412这样我用
regx的模式串为/^a*|b*$/
regx.test("214123412")这句却返回TRUE,匹配长度虽然为0可是我都根据regx.test("214123412")这个的结果来判断是否找到啊,真是奇怪,即然长度为0又怎么会返回TRUE呢? here
RE"^a*" = RE"^"
RE"^" means all line(cause every line has a ^)
match means true whether its match count is zero RE"b*$" work the same way
页:
[1]