I’m trying to get a regexp to solve the next problem:
I have some strings with the next format “somename 1 of 20 and something else” I want to retrieve the “1” from the string
I’m trying with
Pattern pat = Pattern.compile("(?<!of\\s)(\\d+)\\s", Pattern.CASE_INSENSITIVE);
Matcher matcher = pat.matcher(tmp);
But doesn’t work as I was expecting.
The “somename” string can also contain numbers, so basically the logic should be “get the last number before ‘of ‘”
Any tip?
Thanks.
You mean you want to match “
x of y“? Try this: