开发者

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\">([^&开发者_StackOverflow中文版lt;]*)</div>");
Matcher m8 = p8.matcher(responseBody);

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

How?


Are you sure you need regex for it?

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


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

<[^>]*>

and replace it with ''


Try this:

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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜