正则表达式以匹配只能在字符串中出现一次的字符? [英] regular expression to match a character that can only appear once in a string?
本文介绍了正则表达式以匹配只能在字符串中出现一次的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一个正则表达式,如果字符串包含字符*
,则将匹配该正则表达式,但只能匹配一次.它应该匹配a*aa
,aa*aaaaa
,a*aaaa
,但是不应该匹配a**a
,a****
,****
.有什么建议吗?
I'm looking for a regular expression that will match if the string contains the character *
, but only once. It should match a*aa
, aa*aaaaa
, a*aaaa
, but it should not match a**a
, a****
, ****
. any advice?
推荐答案
您可以尝试以下模式:
^[^*]*\*[^*]*$
说明:
^ begining of the string
[^*]* all characters except * zero or more times
\* literal *
[^*]* all characters except * zero or more times
$ end of the string
这篇关于正则表达式以匹配只能在字符串中出现一次的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文