Praveen
Praveen

Reputation: 91175

how to remove the <br/> using regex in java?

how to get value without <br/> tag using regex n java?

my String is:

<Div>
  West Newton, MA 02465
    <br/>USA
</Div>

output should be like:

West Newton, MA 02465
USA

my pattern is like:

Pattern p8 = Pattern
                .compile("<div class=\"leftLabel\">Nickname</div>\\s+<div class=\"rightContent\">([^<]*)</div>");
Matcher m8 = p8.matcher(responseBody);

i didnt get anything as result. what i have to put there(instead of ([^<]*)).

How?

Upvotes: 2

Views: 6150

Answers (5)

TheExplorerLost
TheExplorerLost

Reputation: 155

Try this:

String fixedString = badString.replaceAll("<br(.*?\/?)>", "");

I think this expression will solve the problem. It matches with both line-break combinations.

<br> and <br/>, even with spaces inside them.

Upvotes: 0

codeskraps
codeskraps

Reputation: 1501

replaceAll("<br */>", "");

Upvotes: 1

Andrew Hare
Andrew Hare

Reputation: 351516

Try this:

String fixedString = badString.replaceAll("<br\s*/>", "");

Upvotes: 3

codaddict
codaddict

Reputation: 455020

To get rid of all the tags in the string you can match:

<[^>]*>

and replace it with ''

Upvotes: 3

Ilya Smagin
Ilya Smagin

Reputation: 6152

Are you sure you need regex for it?

why not just remove all tags, e. g. replace '<br/>' with "" or "\n", as you like?

Upvotes: 6

Related Questions