Java Regex to extract numbers and strings from a string

merry :

I want to extract numbers and strings from a string.

Ex.

"TU111 1998 SUMMER”

"TU-232 SU 1999"

"TU232 1999 SUMMER"

I was able to get it using two patterns Pattern.compile("\\d+") and Pattern.compile("[a-zA-Z]+") Is there a way to get it using one pattern?

The expected outcome should be

1=>TU 2=> 111/232 3=>1998/1999 4=>SUMMER/SU

CinCout :

You can just pipe the two regexes together:

[0-9]+|[a-zA-Z]+

Demo

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=10110&siteId=1