The content of my string (MY_STRING)could be in the following format:
bla bla...this is the id of product bla bla:#31 5 2 0000 12please verify bla bla ...
or
bla bla...this is the id of product bla bla: #31 5 2 0000 12, please verify bla bla...
or
bla bla...this is the id of product bla bla: #31 5 2 0000 12 please verify bla bla...
I want to extract out the product ID from the string. The product ID in above example is #31 5 2 0000 12
The format of product ID is that it starts with # which is followed by random numbers (the length is unlimited), the spaces between numbers are arbitrary too.
My current code to extract out product ID is:
Pattern pattern = Pattern.compile("^#\\d+(\\s+\\d+)*$");
Matcher matcher = pattern.matcher(MY_STRING);
if(phoneNrMatcher.find()){
System.out.println(matcher.group(0));
}
But it does not work, could some one help me where goes wrong? Probably the regular expression?
NOTE:
-In my example the content before & after ID #31 5 2 0000 12 is arbitrary.
-product ID string always starts with # which is followed by a number immediately without space or other char