0

I have a regular expression as

[^><]

for not matching the start and close tags

But how can I use this regular expression to do the above checking with allowing only the bold tags like <b> and </b>

Thanks

sharmacal
  • 457
  • 1
  • 6
  • 25
  • 3
    Regular expressions are not a good solution for parsing html / xml. Use a proper parser instead. See http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?rq=1 – p.s.w.g Jan 16 '14 at 16:43
  • Strip all non- `?(?!b\s*>)[^>]+>` if the script supports assertions. –  Jan 16 '14 at 17:34

1 Answers1

1

As pswg states, don't use regular expressions to parse (x|ht)ml.

That said, if you use a regular expression anyway, you will find stripping out not bold tags much easier using:

<\/?[^b]*?>

And simply replacing that with nothing like so: http://regex101.com/r/uY7eK3

Community
  • 1
  • 1
brandonscript
  • 68,675
  • 32
  • 163
  • 220