次の正規表現テストでは、nn/nnnnという形式の日付を探しており、01-12/20nnまたは01 -12/19nn - つまり、1ヶ月に続いて大まかな意味がある年。私が持っているものJavaScript、RegExpオブジェクトはChrome、Firefoxでは動作していますがIE 11では使用できません(正規表現の構文エラー)
はChromeとFirefoxの上で正常に動作しますが、失敗したエラーSyntax error in regular expression
とIE 11
正規表現もwww.regex101.comのテストを合格にし、そこに期待通りに実行したときに、この/^([0-1][0-9][\/]([1][9]|[2][0])[0-9][0-9])$/
です。
私は以下の完全な例を含めました。正規表現が絶対に正しいと確信しているので、私はちょっと立ち往生しています。
何か助けていただければ幸いです。何が間違っていますか?
<!DOCTYPE html>
<html lang="en">
<head>
<title>This is the title</title>
<script type="text/javascript">
var pattern = new RegExp(/^([0-1][0-9][\/]([1][9]|[2][0])[0-9][0-9])$/, 'i');
var goodInput = "12/2012";
var badInput = "1b/g212";
if(!pattern.test(goodInput))
{
console.log("Good Input was NOT OK");
}
else
{
console.log("Good Input was OK");
}
if(!pattern.test(badInput))
{
console.log("Bad Input was NOT OK");
}
else
{
console.log("Bad Input was OK");
}
</script>
</head>
<body>
This is the body
</body>
</html>
文字列を持たないときに 'new RegExp'の必要はありません。 (0)[0-9] [\ /]([1] [9] | [2] [0])[0-9] [0-9])$/i ; ' – epascarello