regex - Extract any 5 digit number from a String using Java -


i'm attempting use regex pull 5 digit number larger string.

here method using returns null.

public void setcwbudgetcode(string webpage){      pattern pattern = pattern.compile("/\\b\\d{5}\b/g");     matcher matcher = pattern.matcher(webpage);     if (matcher.find())         this.cwbudgetcode = matcher.group(); } 

this problem:

pattern pattern = pattern.compile("/\\b\\d{5}\\b/g"); 

instead of use pattern:

pattern pattern = pattern.compile("(\\b\\d{5}\\b)"); 

unlike javascript there no regex delimiter in java , of course no /g

also note have use parenthesis around regex can use matcher.group(1)


Comments

Popular posts from this blog

iphone - Three second countdown in cocos2d -

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -