user3452098
user3452098

Reputation: 298

regex to find words which isn't inside any tags

I have a string sample:

<a href="#location">location</a> <br> word1 :-) <br>

I need to split it so I get a location where I can break this string so It won't break tags as well as words so basically I want to find a space character which isn't inside any tag. I have created a regex to match tags

<\w+.*/\w*?>

how can I exclude it so space between "<a href" doesn't matches.

Update: I need to split this string in 2 without breaking tags and words i.e

<a href="#location">location</a>

&

<br> word1 :-) <br>

Upvotes: 0

Views: 47

Answers (1)

Shub
Shub

Reputation: 2704

Maybe this is what you are looking for:

(?:<(\w+).*?(\/(\1))>|<\w+\/?>|\S+)

<(\w+).*?(\/(\1))> will match for tags like <a> ds</a>
<\w+\/?> will match for <br>,</br> etc
\S+ will match for whole word.

Upvotes: 1

Related Questions