I\'m trying to get the last result of a match without having to cycle through .find()
Here\'s my code:
String in = \"num 123 num 1 num 698 num 19238
Regular expressions are greedy:
Matcher m=Pattern.compile(".*num '([0-9]+) ",Pattern.DOTALL).matcher("num 123 num 1 num 698 num 19238 num 2134");
will give you a Matcher
for the last match, and you can apply it to most regexes by prepending ".*". Of course, if you can't use DOTALL
, you might want to use (?:\d|\D)
or something similar as your wildcard.