Java tutorial
import java.util.regex.Matcher; import java.util.regex.Pattern; public class MainClass { public static void main(String args[]) { Pattern p = Pattern.compile("(\\w+) (\\w+)"); StringBuffer sb = new StringBuffer(); String candidateString = "Jack Lee"; String replacement = "$2, $1"; Matcher matcher = p.matcher(candidateString); matcher.matches(); matcher.appendReplacement(sb, replacement); System.out.println(sb.toString()); } } //