jeudi 23 janvier 2020

Advanced Java RegEx and Pattern matching

private static final String MY_MATCH = "(.+)/my_path/my_file[.](.+)";

The above is working as expected.

However, if my_path is determinable during run-time, does there exist a pre-existing method that "allows" static final? e.g. Maybe similar to Perl run-time code eval.

My solution(pseudo-code):

private static final String MY_MATCH = "(.+)/[unknown_path]/my_file[.](.+)";

static method (String my_path) {
//local var
String my_match = MY_MATCH;
my_match.replace("[unknown_path]", my_path));
Pattern my_pattern = Pattern.compile(my_match);
}

I feel uneasy with the string replace, but I do not see any other solution.

Aucun commentaire:

Enregistrer un commentaire