How do I match the end of a regular expression by a word? For example:
如何用一个词匹配正则表达式的末尾?例如:
<h1><a href=...></a>CONTENT</h1>
Given that <h1>
is the start tag, how do I return <a href=...></a>CONTENT
?
假设
是开始标记,那么如何返回内容?
The expression /< h1>(([<\/h1>\b])*/
does not seem to work
表达式/< h1>([<\/h1>\b])*/似乎不起作用
2 个解决方案
#1
0
What makes most regular expressions difficult, is the fact that they're greedy by default. By making them ungreedy using the U
modifier, writing something like this becomes very trivial. The following should work.
使大多数正则表达式变得困难的是它们默认是贪婪的。通过使用U修饰符使它们变得不贪婪,编写这样的东西变得非常简单。下面的工作。
/<h1>(.*)<\/h1>/U
#2
3
/<h1>([\s\S]*)<\/h1>/
I think this should help you out.
我想这对你有帮助。
#1
0
What makes most regular expressions difficult, is the fact that they're greedy by default. By making them ungreedy using the U
modifier, writing something like this becomes very trivial. The following should work.
使大多数正则表达式变得困难的是它们默认是贪婪的。通过使用U修饰符使它们变得不贪婪,编写这样的东西变得非常简单。下面的工作。
/<h1>(.*)<\/h1>/U
#2
3
/<h1>([\s\S]*)<\/h1>/
I think this should help you out.
我想这对你有帮助。