Javascript正则表达式日期验证文本文件

Javascript正则表达式日期验证文本文件,javascript,regex,Javascript,Regex,每个新句子都以日期开头,所以我想在date regEx上拆分文本 我用过这个表达(我相信这是正确的): 日期总是以这种格式显示,而不是其他格式。文本文件按以下顺序显示: 温丝:你好吗 巴斯:没什么。你呢 这段代码返回null,这很奇怪,我找不到我做错了什么,因为没有什么可以错过的 var chat = "10-05-13 16:14:49: Wence: Hey how you're doing? 10-05-13 16:14:52: Bas: Nothing much. How about

每个新句子都以日期开头,所以我想在date regEx上拆分文本

我用过这个表达(我相信这是正确的):

日期总是以这种格式显示,而不是其他格式。文本文件按以下顺序显示:

温丝:你好吗

巴斯:没什么。你呢

这段代码返回null,这很奇怪,我找不到我做错了什么,因为没有什么可以错过的

var chat = "10-05-13 16:14:49: Wence: Hey how you're doing?

10-05-13 16:14:52: Bas: Nothing much. How about you?"

var date = /(\d{2})-(\d{2})-(\d{4})/;
document.write(chat.match(date));
这个,还有这个,

var  chat = "10-05-13 16:14:49: Wence: Hey how you're doing?

    10-05-13 16:14:52: Bas: Nothing much. How about you?"

var date = /(\d{2})-(\d{2})-(\d{4})/;
document.write(chat.split(date));

两者都返回null。

\d{4}
正在查找四位数字。但年份保存为两位数

尝试:


您正在检查2个数字,后面是破折号,然后是另外2个数字,破折号,然后是4个数字。日期的格式不同。您在正则表达式中使用4位数字表示年份,但在实际日期中仅使用2位数字。更改代码以反映其有效性


/(\d{2})-(\d{2})-(\d{2})/

谢谢,非常愚蠢,我没看到。尽管如此,split函数并没有拆分整个日期,而是拆分日期本身。它返回:“10,05,13”而不是“10-05-13”
var  chat = "10-05-13 16:14:49: Wence: Hey how you're doing?

    10-05-13 16:14:52: Bas: Nothing much. How about you?"

var date = /(\d{2})-(\d{2})-(\d{4})/;
document.write(chat.split(date));
var date = /^(\d\d)-(\d\d)-(\d\d)/;