Quantifier to print only 3 digit numbers in Java regex
1 answer
You need to use a word border \b
:
\b\d{3}\b
See demo
In Java, use double slashes:
String pattern = "\\b\\d{3}\\b";
You don't need to use a capture group around the whole regex, you can access the match via .group()
. See IDEONE demo
+6
source to share