新手问题 正则表达式获取

fstjian · August 09, 2017 · Last by anning0322 replied at August 09, 2017 · 1052 hits

"test1\nw\ntest2\ntest3\n\n2017-08-08 14:12 GMT+08:00 hello [email protected]:" 怎么用正则表达式获取到 2017-08-08 前面的内容。xiexie

str = "test1\nw\ntest2\ntest3\n\n2017-08-08 14:12 GMT+08:00 hello [email protected]:"
str[/^.+(?=2017-08-08)/m]
Reply to aspirewit

hello,如果是日期不确定呢?

套用下楼上的。

str = "test1\nw\ntest2\ntest3\n\n2017-08-08 14:12 GMT+08:00 hello [email protected]:"
str[/^.+(?=([0-9]{4})-([0-9]{2})-([0-9]{2}))/m]
/^[\w\n]+(?=\d{4}-\d{2})/
You need to Sign in before reply, if you don't have an account, please Sign up first.