Import Java.util.regex.matcher;import Java.util.regex.Pattern; Public classregexmatches{ Public Static void Main(String args[]) {//In string lookup by specified modeString line ="This order is placed for qt3000! Ok? "; String pattern ="(. *) (\\d+) (. *)";//Create Pattern ObjectPattern R = pattern.compile (pattern);//Create Matcher object nowMatcher m = r.matcher (line);if(M.find ()) {System. out. println ("Found value:"+ M.Group(0) ); System. out. println ("Found value:"+ M.Group(1) ); System. out. println ("Found value:"+ M.Group(2) ); }Else{System. out. println ("NO MATCH"); } }}
Main steps:
- Constructs the pattern object with regular expressions.
- Building Matcher objects with pattern
- Call to
Matcher.find() get matching results
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Regular Expression Example