0

I want a regex to match everything in a string except "<br>", "<br />", "<br />".

Reason being, i want to put string in a container and want "
" tags to execute and display other tags as they are written by the user.

For example: String-->

"I have <br> <br asked br>  <br />

a <br/> <h1>

<h1<br>>>>>>
<br>>>>>>>>  question  <b .  <a"

it should return :

"I have  <br asked br> 

    a <h1>

    <h1>>>>>
    >>>>>>>  question  <b .  <a"

I already have a regex to find all "br" tags which is (<br\ ?\/?>). Just need a negation of the same.

Mahima
  • 489
  • 1
  • 5
  • 17

1 Answers1

1

Just match the tags you mentioned and then replace it with an empty string.

<br\s*\/?>

DEMO

To match all the br tags except the mentioned ones.

<br(?!\s*\/?>)[^>]*>
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
  • This does not work for me. I want string excluding br tags. This regex just selects all br tags, which i've already done. – Mahima May 29 '15 at 12:42
  • As Avinash told you, you just need to replace the matches by "" – Laurent B May 29 '15 at 12:43
  • @Mahima: The solution above needs to be implemented on the result of your current regex. Using the expression and replacing with an empty string will purge all `
    ` tags from your input.
    – npinti May 29 '15 at 12:44