我想在去年的句子中识别年份,如何在Regex中找到?
对于ex:
字符串=部分文本1999部分文本1986部分文本;
string = Regex.Replace(string, @"(\b(1[7-9]|2[0-9])\d{2}\b)", "<Year>$1</Year>");我的异常输出:
some of texts 1999 some of texts <year>1986</year>注意:一年将不止一次,谢谢,萨兰
发布于 2014-11-26 13:11:37
或者使用这个模式
(.*)(\b(?:1[7-9]|2[0-9])\d{2}\b) 并替换为$1<Year>$2</Year>
Demo
发布于 2014-11-26 12:58:36
\b(\d+)\b(?=[^\d]*$)或
\b((?:1[7-9]|2[0-9])\d{2})\b(?=[^\d]*$)试用<year>$1</year>.See演示版的this.Replace。
http://regex101.com/r/oE6jJ1/20
编辑
\b((?:1[7-9]|2[0-9])\d{2})\b(?!.*\b((?:1[7-9]|2[0-9])\d{2})\b)如果有数字ahead.See演示,请使用此选项。
http://regex101.com/r/oE6jJ1/21
https://stackoverflow.com/questions/27141616
复制相似问题