+ 4

REGEX

Can anybody explain me this regex step by step? String output = output.replaceAll("(?<=[^//b^])([A-Z])", "_$1").toLowerCase();

15th Feb 2020, 12:01 PM
Mateusz Jurkiewicz
Mateusz Jurkiewicz - avatar
1 Respuesta
+ 1
output must be initialised before use it, so String output = "ABCDEFGHX /X/XbX^X"; output = output.replaceAll("(?<=[^//b^])([A-Z])", "_$1").toLowerCase(); System.out.println(output); ([A-Z]) () catch to group $1 [A-Z] upper case character of ALPHABET (?<=[^//b^]) (?<= ) but before it, (positive lookBehind) [^ ] can't be (character, but not one of this..) //b^ one of this characters: / or / or b or ^ .replaceAll(this.., with "_$1") _$1 _ and something in catch group $1 .toLowerCase() convert everything to lower case
15th Feb 2020, 11:32 PM
zemiak