Java Regular Expression, extract 5 digit numbers from a string

This isn’t a java problem - it’s defining your regex correctly; i don’t know the homogeneity of the patterns in your data, but if they are like the input line where you have
XXXXXXXXYXYXYXYXYX...X
then dump the first \\D in your pattern.
There are some great regex resources online so your can figure these things out for yourself - like https://www.freeformatter.com/java-regex-tester.html and https://regexr.com/

3 Likes