regex to exchange two parts

public class Test {

	public static void main(String[] args) {
		String str = "cast('09-04-2008";
		String regex = "(\\d{2})-(\\d{2})";
		System.out.println(str);
		System.out.println(str.replaceAll(regex, "$2-$1"));
	}

}

 

and the result yields: cast('04-09-2008

 

it's meant to exchange the two parts of month and day.

 

and the back reference in java appears to be $n

你可能感兴趣的:(java,Exchange)