user1124535
user1124535

Reputation: 845

Regex matching the end of a string with a word

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

Upvotes: 2

Views: 1192

Answers (2)

kba
kba

Reputation: 19466

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.

/<h1>(.*)<\/h1>/U

Upvotes: 0

FeRtoll
FeRtoll

Reputation: 1267

/<h1>([\s\S]*)<\/h1>/

I think this should help you out.

Upvotes: 3

Related Questions