我不是正则表达式专家,所以我寻求帮助以提出一个可以像这样工作的正则表达式:
var regExp = ???
regExp.exec('\/Date(1330848000000-0800)\/') = [..., '1330848000000', '0800']
// optional gmt
regExp.exec('\/Date(1330848000000)\/') = [..., '1330848000000', null]
regExp.exec('\/Date(1)\/') = [..., '1', null]
// gmt required if - is present
regExp.exec('\/Date(1330848000000-)\/') = null
// escaping backslash is required
regExp.exec('/Date(1330848000000-0800)\/') = null
regExp.exec('\/Date(1330848000000-0800)/') = null
// case sensitive
regExp.exec('\/date(1330848000000-0800)\/') = null
// only numbers allowed
regExp.exec('\/Date(1aaa848000000-0800)\/') = null
regExp.exec('\/Date(1330848000000-0a00)\/') = null
我很早就被这样愚蠢的事情困住了:
/\\bla(.*)bla/.exec('\bla123bla') = null // instead of [ ..., '123']
new RegExp('\\\\bla(.*)bla').exec('\bla123bla') = null // instead of [ ..., '123']