Check for balanced parentheses in a string using a regular expression? Piece of cake try { new RegExp(testString) } catch (e) { return false } return true
-
Show this thread
-
To be clear, this solution works perfectly if it's guaranteed that `testString` *only* contains parentheses. Otherwise you have to strip all the non-parentheses out first
1 reply 0 retweets 14 likesShow this thread
If you don't strip non-parentheses out first, there are a few failure cases: (abc\) - returns false, should be true [abc)(] - returns true, should be false
2:11 AM - 22 Aug 2019
0 replies
0 retweets
9 likes
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.