0

I need a little help. I already tried to practice in several ways, but it didn't work as expected. For example, this one.

I want to match all single words except the pattern <br> in JS.

So I tried

(?!<br>)[\s\S]
(?!<|b|r|>)[\s\S]

The problem I have is, in the ?! quote, it's matching either the first word, < only, not the entire pattern <br>. In reverse, just <br> can match all <br> expect any other words. How can I let it know I want to match the entire word in the ?! quote?

Thank you so much!

Here is what I am trying.

Community
  • 1
  • 1
Micah
  • 4,254
  • 8
  • 30
  • 38

1 Answers1

1

The regular expression you are looking for might look like this:

([^>]|<(?!br>)[^>]+>)+(?=<br>|$)

It should work for any tag, try replacing br by p in the above pattern.

Regex101 link

However, It would be much easier and readable and faster to use:

content.split('<br>').filter(x => x.length)

Hope it helps.

Washington Guedes
  • 4,254
  • 3
  • 30
  • 56
  • I suggested splitting in the very first comment, but OP did not provide any feedback, and I removed it after some 10th comment. Perhaps, there is something else OP is doing "behind the scenes". – Wiktor Stribiżew May 16 '17 at 23:46