Unknown inline modifier Java regex

Viewed 809

i am parsing some text files in which the escape character is ? - There is also 4 escaped characters : + ' : ? . I think the clear escaping was working fine ( might be wrong tho ) until i added spring batch. Now when i try to launch the parsing of the file, this is failing and i don't get why. Here is the error :

java.util.regex.PatternSyntaxException: Unknown inline modifier near index 6
(\?)(?|:|\+|')

And there is the code

private String regex = "(\\?)(?|:|\\+|')";
private String clearEscaping(String s){
    return s.replaceAll(regex, "$2");
}

Can someone explain me why this is not working ? And how should i fix the issue ? Is there any more efficient way to do the escape clearing ?

1 Answers

Thanks to anubhava to point out that my regex was wrong in the 1st place & giving me the fix. Thanks to Wiktor Stribiżew, for the complete solution & make it clear !

=> I changed my regex to "(\\\\?)([?:+'])"

Related