Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression Help??

Status
Not open for further replies.

qajussi

Programmer
Joined
Mar 22, 2004
Messages
236
Location
US
I am trying find and delete a tag.
Say I want <html>, < HTML >, </html>, </ HTML> to be deleted..

There could be one or more spaces between < and h.
They can be upper or lowercases..
esponseString = some html page.
Pattern pattern = Pattern.compile("</?[hH][tT][mM][lL]>", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(responseString);
responseString = matcher.replaceAll("");


Can you help?? please
 
I wouldn't bother with all that ...

Code:
String line = "<html> hello </html>";
line = line.replaceAll("<html>", "").replaceAll("</html>", "").replaceAll("<HTML>", "").replaceAll("</HTML>", "").trim();
System.out.println(line);

--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks..
What if there are some space between < html>
or </ html> like that??

 
damned regex .... witchcraft I tell you !

--------------------------------------------------
Free Database Connection Pooling Software
 
try out this.

public class Test {
public static void main(String[] args) {
CharSequence inputStr = "a< html></ html>cb<html>d< HTML>e</ HTml>";
String patternStr = "</?\\s*html>";

Pattern pattern = Pattern.compile(patternStr,Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);

String result = matcher.replaceAll("");
System.out.println("result : " + result);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top