Spearfisher
Spearfisher

Reputation: 8773

Regex to get everything between 2 words

I am trying to get through a lot of content and to extract some data from it. Therefore I need to pick the information between 2 set of characters.

It looks like this

***some text*** li> ***data to capture*** </li ***more text***

What regex can I use to get everything that is enclosed between li> and </li ?

Upvotes: 2

Views: 161

Answers (1)

hata
hata

Reputation: 12478

Basically it will be like this:

li>(.*?)(?:</li)

Depending on your language environment, certain characters may need to be escaped or the way of retrieving the matched string may differ. Typically you would need to escape / by prepending a backslash, resulting in this new version:

li>(.*?)(?:<\/li)

Here's a live demo: https://regex101.com/r/zV4uN6/1

Upvotes: 1

Related Questions