新手问题 正则表达式获取

fstjian · 2017年08月09日 · 最后由 anning0322 回复于 2017年08月09日 · 1051 次阅读

"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]
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})/
需要 登录 后方可回复, 如果你还没有账号请 注册新账号