【发布时间】:2019-10-05 14:36:38
【问题描述】:
我已经完成了一个非常基本的步骤,它检查是否存在一个特殊字符。下一步需要一些建议,因为我希望能够在找到 # 后从 1 个位置开始搜索另一个特殊字符。
var reg = /#/;
alert(reg.test(string))
例如:
abc#.123 //invalid - as . is immediately after #
abc#12.3 //valid - as . is more than 1 character after #
abc#abcd.23 //valid - as . is more than 1 character after #
a#123.12 //valid - as . is more than 1 character after #
a#12123124.12 //valid - as . is more than 1 character after #
abcd#1231.09 //valid - as . is more than 1 character after #
1.23#12312.01 //invalid - as . is before #
123#122.01#12 //invalid - as there is another# after .
因此# 和. 之间的间隔应始终为1 个或多个字符,# 始终排在第一位。
【问题讨论】:
-
你的意思是像
#..([!@#$%^&*()])regex101.com/r/HZoWko/1 -
试试
^[^#.]*#.+\.。在此处查看现场演示regex101.com/r/W6rA75/1
标签: javascript regex regex-negation regex-lookarounds regex-greedy