Mysql 正则表达式匹配 <year>、<year_0>、<year_1> 标签中的相同子字符串

Mysql regexp match same substring in <year>, <year_0>, <year_1> tags

问题:是否可以让正则表达式匹配 >*2014*</year 子字符串,以便只有最近的 > 字符是匹配的开始。另一种说法是使用正则表达式匹配 >...XXXX...</year 子字符串,但不允许在子字符串匹配中使用 < 字符。

Mysql regexp 查询到 select year=2014 记录,但这会溢出开始结束标记 >*2014*</year 和 returns 额外的行。我相信它从早期的 <start>2014-MM-DD</start> 标签开始匹配。

Select * From table1 Where args REGEXP '>.*(2014).*<\/year'

我不使用的原因 '<year>.*(2014).*<\/year>' 是一年或更长时间, year_0, year_1 标签等数组标签的数量是无限的。我需要 select 年份(包含)2014 的任何行,无论哪个可用年份标签值是 .

简化示例 args 列值,每一行都是单独的 table 行。标签值不仅仅是 year (equals) 2014 而是 any year (contains) 2014 公式。

<title>Record 1</title><start>2014-01-31</start><year>text 2013 text</year><end>2014-02-17</end>
<title>Record 2</title><start>2014-01-03</start><year>any 2014 text</year><end>2014-01-26</end>
<title>Record 3</title><start>2014-03-07</start><year>aa 2015 bb</year><end>2014-03-12</end>
<title>Record 4m</title><start>2014-02-22</start><year>2014</year><year_0>like 2015 this</year_0><end>2014-03-01</end>
<title>Record 5m</title><start>2015-02-23</start><year>bb 2012 cc</year><year_0>2014 dd</year_0><year_1>2014</year_1><end>2015-03-02</end>
<title>Record 6m</title><start>2014-02-22</start><year>2013</year><year_0>like 2015 this</year_0><end>2014-03-01</end>
<title>Record 7m</title><year>2013</year><start>2014-02-22</start><year_0>like 2015 this</year_0><end>2014-03-01</end>

这里regex101.com online example显示溢出问题,我需要匹配year,year_0,year_1等等标签<year> 标签。这不应该匹配记录,因为年份有 2013、2015 子字符串。

编辑这里也是SqlFiddle online example显示溢出问题any_year=2014匹配不正确的行,我只需要匹配 year,year_0,year_1,... 数组值。不应列出第 7m 行。

Edit2 目前为止我认为的最佳答案是 Where args REGEXP '<year[>_].*2014.*<\/year[>_]' 在单个正则表达式中查找年份值数组。

你只需要用反斜杠转义斜杠 \/

http://sqlfiddle.com/#!9/0bbb0/8

SELECT * 
FROM t1
WHERE args REGEXP '<year>.*2014.*<\/year>'

更新 http://sqlfiddle.com/#!9/0bbb0/9

SELECT * 
FROM t1
WHERE args REGEXP '<year.*>.*2014.*<\/year.*>'