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
Post a Comment