正则表达式可以实现吗?
发布时间:2020-12-14 05:49:47 所属栏目:百科 来源:网络整理
导读:是否可以使用与以下内容匹配的正则表达式匹配器: 我需要知道是否存在匹配括号内部和外部的子字符串,格式为(@ …) 匹配的例子: abc(@ abc) abc(@( abc)) abc( def(@ abc)) (( abc def)(@ abc)) ( def( abc)(@ abc)) 不匹配的例子: abc (@ abc) abc(@ def)
是否可以使用与以下内容匹配的正则表达式匹配器:
我需要知道是否存在匹配括号内部和外部的子字符串,格式为(@ …) 匹配的例子: > abc(@ abc) 不匹配的例子: > abc 编辑: “(@ abc)abc”应该匹配 “(@ abc)(@ abc)”不应该匹配 describe "regex" do let(:regex) { /(.+).*(@.*1.*)/ } matches = ["abc (@ abc )","(@ abc ) abc","abc (@ (& abc ) )","abc (@ (& abc ) )"] no_matches = ["abc","(@ abc )","abc def","abc abc","abc (& abc)","(@ abc ) (@ abc)"] matches.each do |flow| it "should match '#{flow}'" do flow.should match regex end end no_matches.each do |flow| it "should not match '#{flow}'" do flow.should_not match regex end end end 解决方法
尝试使用正则表达式模式
/(?=.*?(?<!@ )(bw+b)).*(@.*1.*)/ 见this test code. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |