Skip to content
Advertisement

Preg_match string inside curly braces tags

I’d like to grab a string between tags. My tags will be with curly braces.

JavaScript

So far I have found #<s*?$tagnameb[^>]*>(.*?)</$tagnameb[^>]*>#s This one matches tags with angle brackets <>. I couldn’t figure out how to make it look for curly braces.

Eventually I would like to parse whole page and grab all matches and build an array with strings.

This is the code:

JavaScript

Advertisement

Answer

Replace all occurrences of < and > with { and } and change preg_match() to preg_match_all()` to catch multiple occurrences of text inside those tags.

JavaScript

Forget about what I mentioned about escaping the curly brackets – I was mistaken.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement