Regex Non-Greedy (Lazy)

我们两清 提交于 2019-11-28 10:50:24

The regex you want is <TD[^>]*>:

<     # Match opening tag
TD    # Followed by TD
[^>]* # Followed by anything not a > (zero or more)
>     # Closing tag

Note: . matches anything (including whitespace) so [.\s]*? is redundant and wrong as [.] matches a literal . so use .*?.

For non greedy match, try this <TD.*?>

From https://regex101.com/

  • * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
  • *? Quantifier — Matches between zero and unlimited times, as few times as possible, expanding as needed (lazy)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!