.. with Java Standard Library!
RegexHello.java
And the output is..
RegexHello.java
import java.util.regex.Pattern; import java.util.regex.Matcher; public class RegexHello { public static void main(String[] args) { final String phoneNumberRegex = "((\\d){3}-(\\d){1,4})"; final String haysack = "454-3fdasfr456-324fasadfad454-431312343-43dsfafads"; final Pattern phoneNumberPattern = Pattern.compile(phoneNumberRegex); final Matcher matcher = phoneNumberPattern.matcher(haysack); while(matcher.find()) { System.out.println(matcher.start() + "\t- " + matcher.group()); } } }
And the output is..
0 - 454-3 11 - 456-324 26 - 454-4313 36 - 343-43