Java Pattern compile() MethodThe compile() method of Pattern class is used to compile the given regular expression passed as the string. It used to match text or expression against a regular expression more than one time. Signature
Parameterregexp - The expression that we want to compile. flags - Match flags, a bit mask that may include ReturnsThe given regular expression compiled into a pattern ThrowsPatternSyntaxException - If the expression's syntax is invalid Example 1Test it NowOutput: Result : java.util.regex.Matcher[pattern=@gmail region=0,13 lastmatch=@gmail] Example 2Test it NowOutput: Start : 3, End : 9 Pattern group : @gmail Start : 12, End : 18 Pattern group : @gmail Start : 21, End : 27 Pattern group : @gmail number of Matches: 3 Example 3Test it NowOutput: Result : java.util.regex.Matcher[pattern=@Gmail region=0,13 lastmatch=@gmail] Example 4Test it NowOutput: Start : 0, End : 1 Pattern group : Start : 4, End : 5 Pattern group : number of Matches: 2
Next TopicJava Regex
|