Package com. regxs; import java. util. arrays; import java. util. regex. matcher; import java. util. regex. pattern;/*** regular expression, predefined Character Set [\ D] * @ author one **/public class regxDefine2 {public static void main (String [] args) {String phoneNum = "400-95588,400-110,400-119,400-83765566"; String regx = "\ D";/* value 0-9: \ d */Pattern phone = Pattern. compile (regx); Matcher matcher = phone. matcher (phoneNum); char [] marker = new char [phoneNum. length ()]; Arrays. fill (marker, ''); while (matcher. find () {System. out. println ("Start:" + matcher. start () + "end:" + matcher. end (); Arrays. fill (marker, matcher. start (), matcher. end (), '^');} System. out. println (phoneNum); System. out. println (marker );}}
This article from the "bubble do not add water" blog, please be sure to keep this source http://regex.blog.51cto.com/8006867/1305481