Javascript 可选结束捕获组
我尝试总共有三个捕获组,其中最后一个是可选的。我遇到了一个问题,我不确定如何从最后一个组中排除最后一个分隔符,并让它查找到底 这是我的模式Javascript 可选结束捕获组,javascript,regex,Javascript,Regex,我尝试总共有三个捕获组,其中最后一个是可选的。我遇到了一个问题,我不确定如何从最后一个组中排除最后一个分隔符,并让它查找到底 这是我的模式 /(.+)\@(.+)\:(.+)/ 下面是我的示例字符串 test@hello // => ['test', 'hello'] test@hello:optional // => ['test', 'hello', 'optional'] 使用string.split string.split(/[:@]/) [:@]匹配冒号或@符号,然
/(.+)\@(.+)\:(.+)/
下面是我的示例字符串
test@hello // => ['test', 'hello']
test@hello:optional // => ['test', 'hello', 'optional']
使用string.split
string.split(/[:@]/)
[:@]
匹配冒号或@
符号,然后split函数根据匹配的字符拆分字符串
var='s'test@hello:optiona'
警报(s.split(/[@::]/)
使用string.split
string.split(/[:@]/)
[:@]
匹配冒号或@
符号,然后split函数根据匹配的字符拆分字符串
var='s'test@hello:optiona'
警报(s.split(/[@::]/)
仅显示如何修复模式:。仅显示如何修复模式:。