0

我正在使用以下正则表达式从 html 页面中提取日期:

(((0?[1-9]|[1-2][1-9]|[123]0|31)(/|.|'|:|,|\s|-)(0?[13578]|1[02])(/|.|'|:|,|\s|-)\d{4})|((0?[2-9]|[0?1]1|[1-2][1-9]|[123]0)(/|.|'|:|,|\s|-)(0?[13456789]|1[0-2])(/|.|'|:|,|\s|-)(\d{4}))|((0?[1-8]|[1-2][0-8]|[0?1]9)(/|.|'|:|,|\s|-)(0?2)(/|.|'|:|,|\s|-)(\d{4}))|(29(/|.|'|:|,|\s|-)0?2(/|.|'|:|,|\s|-)((19(0[048]|[2468][048]|[13579][26]))|([2-9]\d{1}([2468][048]|[13579][26]|00)))))(.*|\w*|\s*)([01]?\d)|(2[0-3])(:|\.|-|'|\/|\s)[0-5]?\d{2}"); //dd-mm-yyyy hhh:mm:ss

上面的正则表达式提取具有不同分隔符的 dd mm yyyy h mm ss 格式的日期。

我从 match.value 得到的输出如下所示:

11/09/2013&nbsp;at&nbsp;09:48</b></td> that is it matches everything from the response that follows the match.

但我只希望 match.value 的结果应该是这样的:

11/09/2013 09:48

所以我的表达基本上是它匹配日期之后的所有内容,这不是我的要求,我需要它应该只匹配文本框中提到的日期和时间。

请帮助我如何更改我的正则表达式以满足我的要求。

4

1 回答 1

0

尝试将这些添加到您的逻辑 (<[^<]+?>)+ 以删除 HTML 标记和 (&[^;]+?;)+ for  .

编辑:

text = Regex.Replace(text, "<[^<]+?>" ,"");
text = Regex.Replace(text, "(&[^;]+?;)+", "");
text = text.Trim();
text = text.Remove(17);
于 2013-09-19T06:51:18.523 回答