正则表达式之间获取文本

时间:2014-03-15 11:26:09

标签: regex

我有一个包含这个(和其他东西)的字符串:

the text<br> 
Text text text and mooore text...<br> 
Text text text and mooore text...<br>
Text text text and mooore text...<br>

我需要一个注册表来获取<br>代码和第一个文字之间的文字。

1 个答案:

答案 0 :(得分:0)

假设你想要这个:

the text<br>\nText text text and mooore text...<br> 
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

正则表达式: (?:<br>)([\s\S]*?)(?=<br>)

  1. (?:<br>) - &gt;确保<br>存在(不匹配)
  2. ([\s\S]*?) - &gt;懒洋洋地匹配所有内容并捕获它。
  3. (?=<br>) - &gt;确保跟随<br>
  4. Demo

    P.S。正如其他人所说,您无法将HTML标记解析为answered here

相关问题