I was learning the regex
part of Java recently , and today I met a problem about the use of boundry \\G
, Here is my code :
String input = "abcdec";
System.out.println(String.format("Before :'%s' ; after replace : '%s'", input , input.replaceAll("\\Gx?", "!")));
while it print Before :'abcdec' ; after replace : '!abcdec'
, I don't know why it print this , after its first match with the beginning of the string , it replace the place with a char '!' , but then why can't it match again?I think the Regex Expression '\Gx?' could match every place.
I need your help , each help is appreciated!Thanks..