Ren Li
Ren Li

Reputation: 11

Remove strings between brackets and the bracket itself

I have this data:

<div><b>CANADA INC.</b></div>

I want to remove everything between <> and the <> itself.

I want it to look like:

CANADA INC.

Can I use RegEx to do the trick?

Upvotes: 0

Views: 37

Answers (1)

Kaspar Lee
Kaspar Lee

Reputation: 5596

First of all, note that you should not really use RegEx to parse HTML. You should see if the language you are using supports parsing HTML, or maybe find a plugin to so do it.

Now we have that over and done with, there are 2 ways of doing this:

Method 1

<[^>]*>

Live Demo on RegExr

How it works:

<        # Opening <
[^>]*    # Any character except a > any number of times
>        # Closing >

Method 2

<.*?>

Live Demo on RegExr

How it works:

<        # Opening <
.*       # Any character any number of times
?        # Make sure the expression is not greedy (and select the entire string)
>        # Closing >

Upvotes: 1

Related Questions