I'm trying to create a regex to find a string with a double-underscore __
, multiple underscores _
and then another double-underscore __
and extract the part before the final __<string>
The first delimiter should be __
and then multiple _
, and string ends with __<String>
The result should be such that string before the second __
example 1- UK__SATHISH_KUMAR__LONDON
should result to UK__SATHISH_KUMAR
example 2- UK__SATHISH_KUMAR_MALE__LONDON
should result to UK__SATHISH_KUMAR_MALE
public static final String RULE_FILE_NAME_PATTERN =
"(([a-zA-Z]+)__(([a-zA-Z]+_[a-zA-Z]+_[a-zA-Z]+_[a-zA-Z]+)|([a-zA-Z]+_[a-zA-Z]+_[a-zA-Z]+)|([a-zA-Z]+_[a-zA-Z]+)|([a-zA-Z]+)))(__[\\w]+)*";
This pattern works but fails sonarqube as it's long, can some one help to get a shorter regex?