【发布时间】:2022-10-02 00:00:38
【问题描述】:
我想在字符串中找到如下匹配:
-
s = \'()\' -> 结果应该是
true -
s = \'(]\' -> 结果应该是
false -
s = \'()[]{}\' 结果应该是
true -
s = \'([])\' 结果应该是
true -
s = \'{([])}\' 结果应该是
trueconst isValid = (s) => { //how to return the value? } console.log(isValide(\'[]\') //should be true
-
如果您想使用比 RegEx 效率低但也更简单的东西,您可以使用堆栈(即带有
.pop()的数组),如下所述:stackoverflow.com/questions/50318277/how-to-validate-brackets
标签: javascript regex