新手问题 如何写出这样的正则表达 '小明 2015/2/15 15:21:55'

luffycn · February 15, 2015 · Last by Rei replied at February 15, 2015 · 1872 hits

要在一堆这样的文本中

小明 2015/2/15 15:21:55 chat content 1

小王 2015/2/15 15:22:06 chat content 2

匹配 '小明 2015/2/15 15:21:55'

^[\u4E00-\u9FA5]+[\s][\d{4}\/\d{1,2}\/\d{1,2} \d{2}:\d{2}:\d{2}]

为何这样不行?

中文 ^[\u4E00-\u9FA5]+ 空格 [\s] 日期时间 [\d{4}\/\d{1,2}\/\d{1,2} \d{2}:\d{2}:\d{2}]

把这三个加一起,怎么匹配不出来

str.scan /^小明.*$/
 => ["小明 2015/2/15 15:21:55"]

/^\p{Han}+\s\d{4}\/\d{1,2}\/\d{1,2}\s\d{2}:\d{2}:\d{2}$/

You need to Sign in before reply, if you don't have an account, please Sign up first.