how to appendReplace multiple values in java.util.regex
Sanju
Ranch Hand
Joined: Jul 15, 2002
Posts: 53
posted
0
hi friends..
How to appendReplace multiple values in java.util.regex.I did single value in java.util.regex. plz send one example for multiple value purpose THis is single appendReplace value code import java.util.regex.*; public class AllData {
public static void main(String args[])throws Exception {
// Pattern p = Pattern.compile("<a href"); String lower="<a href"; Pattern p = Pattern.compile(lower); String strlow="this is to test <a href=http://www.k7mail.com>k7mail.com</a> <A HREF=http://www.k2mail.com> k2mail.com </a> ";
String upper="<A HREF"; String fill=" "; fill=strlow.replaceAll(upper,lower); //fill=strlow.replaceFirst(upper,lower); StringBuffer buf = new StringBuffer(fill); // StringBuffer buf = new StringBuffer(sb1.toString()); // System.out.println("This the normal Text "+buf.toString()); Matcher m = p.matcher(buf.toString()); // System.out.println("mmmmmmm:"+buf.toString()); String kk=buf.toString(); //if(kk.equalsIgnoreCase("HREF")) //{ StringBuffer sb = new StringBuffer(kk); while(m.find(0)) { m.appendReplacement(sb,"target=_blank href"); } m.appendTail(sb); System.out.println("The output is "+sb.toString()); //}
} }
Thank you,<br />Sanju
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
posted
0
This is a duplicate of your question in Intermediate. Please don't -- it will cause 'ranchers to waste time on giving duplicate answers, time they could've spent helping someone else. - Peter
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
posted
0
Closing this. Respond to the thread in JIG Intermediate.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
subject: how to appendReplace multiple values in java.util.regex