Java-Non Capturing Groups

Non Capturing Groups Groups beginning with (?: are either pure, non-capturing groups that do not capture text and do not count towards the group total, or named capturing group.   Program Program Source import java.util.regex.Pattern; import java.util.regex.Matcher; public class Javaapp { public static void main(String[] args) { Pattern pat = Pattern.compile(“([0-9]{2})(?:[0-9]{2})([0-9]{4})”); Matcher mat = pat.matcher(“1022199009282010″); … Read more…

Java-Name Capturing Groups

Name Capturing Groups We can use name capturing groups using ?<name> in front of the regex capturing group. Then we can refer to such group using given name. Program Program Source import java.util.regex.Pattern; import java.util.regex.Matcher; public class Javaapp { public static void main(String[] args) { Pattern pat = Pattern.compile(“(?\\w+)\\s+(?\\w+)”); Matcher mat = pat.matcher(“TamilNadu Chennai Delhi … Read more…

Java-Rearranging Captured Group

Rearranging Captured Group The appendReplacement() method has special provision for recognizing references to capturing groups in the replacement text string. If $n, where n is an integer, appears in the replacement string, it is interpreted as the text corresponding to group n. You can therefore replace the text matched to a complete pattern by any … Read more…