Simple Regex replace in java and Striptags


2007-08-20 Digg! icurtain Delcious icurtain

replacing two chars using an or (pipes)

String p = "text to search.. through with = and , and ^

regex

";

System.out.println("result: "+ p.replaceAll(",|=", "") );

if you want to strip all the tags out you can use:

System.out.println("p: "+ p.replaceAll("\\W", " ") );

note.. that will strip spaces too hence we are replacing with " "

to strip tags properly and remove what's between them use

System.out.println("p: "+ p.replaceAll("<[^>]+>", "") );