Category: 14. Java Regex

  • Examples Matching Characters

    Following are various examples of matching characters using regular expression in java. Sr.No Construct & Matches 1 xThe character x 2 \\The backslash character 3 \0nThe character with octal value 0n (0 ≤ n ≤ 7) 4 \0nnThe character with octal value 0nn (0 ≤ n ≤ 7) 5 \0mnnThe character with octal value 0mnn…

  • PatternSyntaxException 

    Introduction The java.util.regex.PatternSyntaxException class represents a unchecked exception thrown to indicate a syntax error in a regular-expression pattern. Class declaration Following is the declaration for java.util.regex.PatternSyntaxException class − Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career. Constructors Sr.No Method & Description 1 PatternSyntaxException(String desc, String regex, int index)Constructs a…

  • Matcher Class

    Introduction The java.util.regex.Matcher class acts as an engine that performs match operations on a character sequence by interpreting a Pattern. Class declaration Following is the declaration for java.util.regex.Matcher class − Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career. Class methods Sr.No Method & Description 1 Matcher appendReplacement(StringBuffer sb, String…

  • Pattern Class

    Introduction The java.util.regex.Pattern class represents a compiled representation of a regular expression. Class declaration Following is the declaration for java.util.regex.Pattern class − Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career. Field Following are the fields for java.util.regex.Duration class − Class methods Sr.No Method & Description 1 static Pattern compile(String regex)Compiles the…

  • MatchResult Interface

    Introduction The java.util.regex.MatchResult interface represents the result of a match operation. This interface contains query methods used to determine the results of a match against a regular expression. The match boundaries, groups and group boundaries can be seen but not modified through a MatchResult. Interface declaration Following is the declaration for java.util.regex.MatchResult interface − Learn Java in-depth with real-world projects through…

  • Capturing Groups

    Capturing groups are a way to treat multiple characters as a single unit. They are created by placing the characters to be grouped inside a set of parentheses. For example, the regular expression (dog) creates a single group containing the letters “d”, “o”, and “g”. Capturing groups are numbered by counting their opening parentheses from…

  • Overview

    Java provides the java.util.regex package for pattern matching with regular expressions. Java regular expressions are very similar to the Perl programming language and very easy to learn. A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a…