How do you check, in JavaScript, if a string is a proper regular expression that will compile?
For example, when you execute the following javascript, it produces an error.
var regex = new RegExp('abc ([a-z]+) ([a-z]+))');
// produces:
// Uncaught SyntaxError: Invalid regular expression: /abc ([a-z]+) ([a-z]+))/: Unmatched ')'
How does one determine if a string will be a valid regex or not?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…