【发布时间】:2021-12-18 18:15:15
【问题描述】:
我想检查一个字符串是否匹配以下模式
文本包含两个",每个文本可以通过; 分隔,附加;是强制性的
我尝试使用正则表达式/"(.*?)";?/,但无法正常工作
在test3下面的代码sn-p中返回true但不应该匹配正则表达式
我不知道这是我的正则表达式还是我尝试我的正则表达式的方式
const regex = /"(.*?)";?/;
const test = `"hello"; "world";`;
const test2 = `"hello"; "world"`;
const test3 = `"hello; "world"`;
const test4 = `"hello"; world`;
const test5 = `"hello""world"`;
//should be true
console.log("test1",regex.test(test));
console.log("test2",regex.test(test2));
//should be false
console.log("test3",regex.test(test3));
console.log("test4",regex.test(test4));
console.log("test5",regex.test(test5));
【问题讨论】:
-
你可以在这里测试:regex101.com/r/fsAOqR/1
标签: javascript regex string comparison