Reputation: 7622
I have string that can contain almost any character including (_- %
and so forth. The string ends with (\d{1,2})
. Eg. parenthesis with 1 or 2 digits. I now want 2 capturing groups, the 2 digits and everything before the parenthesis.
currently I have:
final Pattern pattern = Pattern.compile("^([-%\\(\\)_/= a-zA-Z\\d]+)\\((\\d{1,2})\\)$");
But this does not match everything. I want to replace the char group with .*
but not have it match the (\d{1,2})
at end of string. How can I achieve this?
Upvotes: 3
Views: 132
Reputation: 48404
If I understand your question, you can use a reluctant quantifier .*?
instead of your greedy quantifier .*
to match everything reluctantly before your second catpure group.
Upvotes: 6