The moose likes Java in General and the fly likes how to appendReplace multiple values in java.util.regex Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

how to appendReplace multiple values in java.util.regex

Sanju
Ranch Hand

Joined: Jul 15, 2002
Posts: 53
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
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
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
 
IntelliJ Java IDE
 
subject: how to appendReplace multiple values in java.util.regex
 
Threads others viewed
Regular expressions ... Pls help
java.util.regex.PatternSyntax Exception
Java regex?
hi how can I appendReplace multiple values in java.util.regex
hi priya see this question...
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture