我需要一个正则表达式来避免以“+”和“-”开头或结尾的字符串。这是我的表达:
^[^+-]*[^+-]$
这样对吗?看起来它正在工作,但我没有测试它的属性,所以我不确定。
^(?![+-]).*(?![+-]).$
^(?![+-]) ### assert that the first character is not "+" or "-"
.* ### match any character zero or more times
(?![+-]).$ ### assert that the last character is not "+" or "-"
您可以在这里尝试正则表达式:https : //regex101.com/r/ZxguTc/1
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句