Say I have some String
object containing "This sentence was written on 2020-03-21 by person 1234567 at 07:23 hours"
.
How would I extract ONLY the "1234567"
part of the string?
Maybe using a solution from this Extract digits from string - StringUtils Java question, but I don't know how to limit the extracted numbers only on the desired sequence.
If I would use the str.replaceAll("[^0-9]", "")
on this string, I would get "2020032112345670723"
which means that it extracts ALL of the numbers in a string, but I want ONLY the sequence containing a certain number of digits (in my case 7).
Also, the sequence will not always be in the same place, so using substring(index from, index to)
will not work.