Assuming a target string that’s on one hand arbitrary but, on the other hand, guaranteed to contain a single decimal number (1 or more digits), I came up with the following regular regex pattern:
.*?(\d+).*?
So, if the target string is “(this is number 200)”, for example, Matcher.group(1) will contain the number.
Is there a more optimal regex pattern (or non-regex method) to extract this number?
By “optimal” I mean fastest (possibly with the least amount of CPU cycles). Java only.
I am sure regex and parseInt will perform well enough for you. However for your interest, I have compared it with a simple loop.
prints