2017-06-15 62 views
0

JavaScript RegEx構文違反の可能性のあるエラーメッセージの包括的なリストはありますか?すべてのJavaScriptの "Uncaught SyntaxError:Invalid regular expression"メッセージのリスト

try { 
    new RegExp(pattern); 
} catch (e) { 
    console.log(e.message); 
} 

は例えば、いくつかの可能性のあるエラーメッセージは、次のとおりです。

Uncaught SyntaxError: Invalid regular expression: /(/: Unterminated group 
Uncaught SyntaxError: Invalid regular expression: /+/: Nothing to repeat 
Uncaught SyntaxError: Invalid regular expression: /\/: \ at end of pattern 
+0

このようなリストにはどのような用途がありますか? – Amy

+0

これはブラウザ固有のものです。おそらくエンジンのソースコードを調べなければならないでしょう。 –

+0

ユースケースは、正規表現バリデーターで表示するエラーの理由の最大長を知ることです。サイジング推定のためのモーダルウィンドウ –

答えて

1

ChromeのV8エンジンのソースコードregexp-parser.cc

"Regular expression too large" 
"Unterminated group" 
"Unmatched ')'" 
"Nothing to repeat" 
"Invalid group" 
"Too many captures" 
"\\ at end of pattern" 
"Invalid property name" 
"Invalid escape" 
"Invalid decimal escape" 
"Invalid unicode escape" 
"Lone quantifier brackets" 
"numbers out of order in {} quantifier" 
"Incomplete quantifier" 
"Invalid Unicode escape sequence" 
"Invalid capture group name" 
"Duplicate capture group name" 
"Invalid named reference" 
"Invalid named capture referenced" 
"Invalid class escape" 
"Invalid property name in character class" 

21件の別個のエラー・メッセージ、および最長40個の文字です。


Mozilla SpiderMonkeyエンジンソースコードjs.msg

"back reference out of range in regular expression" 
"invalid range in character class" 
"\\ at end of pattern" 
"RegExp exec method should return object or null" 
"invalid decimal escape in regular expression" 
"invalid regexp group" 
"invalid identity escape in regular expression" 
"invalid unicode escape in regular expression" 
"unterminated parenthetical" 
"can't supply flags when constructing one RegExp from another" 
"nothing to repeat" 
"numbers out of order in {} quantifier." 
"character class escape cannot be used in class range in regular expression" 
"raw brace is not allowed in regular expression with unicode flag" 
"raw bracket is not allowed in regular expression with unicode flag" 
"too many parentheses in regular expression" 
"Unicode codepoint must not be greater than 0x10FFFF in {0}" 
"unmatched) in regular expression" 
"unterminated character class" 

19個のエラーメッセージがあり、最長の文字数は74文字です。

1

それはjavascriptのエンジンに依存します。 V8エンジンのブラウザ用の例えば

はすべてのエラーのため、このパターンReportError(CStrVector(ためregex parser source

検索をご確認ください。

また、パーサーのポインタとして参照されるメッセージの場合はhereです。

+0

ありがとう!これは私がやったことです。 –

+0

@JoshBroadhurst私はアンサーチェックplsを更新しました –

関連する問題