views:

176

answers:

3

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?

+1  A: 

Try this:

String fixedString = badString.replaceAll("<br\s*/>", "");
Andrew Hare
`i broke<br      />your replaceAll`
KennyTM
@KennyTM - Well played! :)
Andrew Hare
@KennyTM - fixed now.
Andrew Hare
+3  A: 

Are you sure you need regex for it?

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

portland
Fun fact, here's the full source for `String#replaceAll`: `public String replaceAll(String regex, String replacement) { return Pattern.compile(regex).matcher(this).replaceAll(replacement); }`. Simple replacement is just fine though.
Esko
+2  A: 

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

<[^>]*>

and replace it with ''

codaddict
`i broke<!-- 3<π -->your replaceAll`
KennyTM