It looks like you want to do a regex-powered replacement on some string, right? This code using java.util.regex works for me:
Code:
import java.util.regex.*;
public class StringMatch {
public static void main(String[] args) {
Pattern p = Pattern.compile("foo");
for (int i = 0; i < args.length; i += 1) {
System.out.println(p.matcher(args[i]).replaceAll("bar"));
}
}
}
It goes through each argument and replaces each occurrence of "foo" with "bar".
First you have to create a regex Pattern object using the Pattern class' static compile() method. Then call p.matcher(String) to get a Matcher object from that pattern, ready to process whatever string you pass as an argument. Then you can call a function on the Matcher, which does whatever you want. replaceAll(String) does a substitution and returns a new string. matches() just returns true or false. You can even get grouped-match results using the group(int) function.