我想找到字符串,其最后一个字符可能出现也可能不出现
"abc,efg,ASD"
"abc,ASD,efg"
所以,我必须找到有或没有“,”
的ASD答案 0 :(得分:2)
[,"](ASD)[,"]
此正则表达式将执行以下操作:
现场演示
https://regex101.com/r/mV9vA9/1
NODE EXPLANATION
----------------------------------------------------------------------
[,"] any character of: ',', '"'
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
ASD 'ASD'
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
[,"] any character of: ',', '"'
----------------------------------------------------------------------
答案 1 :(得分:0)
这会回答你的问题吗?
var regex = /,ASD,?/g;
var result = regex.exec("abc,ASD\nabc,ASD,dsa");
console.log(result);