我不是正则表达式高手,所以我想寻求帮助来设计一个可以按照以下规则工作的正则表达式:
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']
/
不需要转义。 - nhahtdh