I would like to remove all the occurrences of angle brackets and the text in between, from my string. So given the following:
<a target="_blank" href="http://en.wikipedia.org/wiki/Grand_Theft_Auto_%28series%29">Grand Theft Auto</a> is a video game series created and primarily developed by Scottish developer Rockstar North, published in 1998.
I need this:
Grand Theft Auto is a video game series created and primarily developed by Scottish developer Rockstar North, published in 1998.
I have tried using the following, which doesn't seems to change the original string at all:
string.replaceAll("<.*?>","");
Java strings are immutable , and don't change by themselves . You need to change them. Change this:
string.replaceAll("<.*?>","");
To this:
string = string.replaceAll("<.*?>","");
Try
String str = string.replaceAll("\\<.*?\\>", "");
Edit: Correction made @John Hascall comment.
String tmp = yourString.replaceAll("<a.*?>", "");
String finalString = tmp.replaceAll("</a>,"");
System.out.print(finalString);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.