Java regular expressions common matching symbols
There are several common matching symbols or metacharacters that can be used in regular expressions in Java to match certain types of characters or groups of characters:
.
- The dot metacharacter matches any character except a line break.[]
- The square brackets are used to create a character class, which matches any one character in the set of characters enclosed within the brackets. For example,[abc]
matches any character that is either a, b, or c.^
- The caret symbol at the beginning of a character class negates the match, so that it matches any character that is not in the set of characters enclosed within the brackets. For example,[^abc]
matches any character that is not a, b, or c.$
- The dollar sign matches the end of the input string.*
- The asterisk matches zero or more occurrences of the preceding character or group. For example,a*
matches zero or more occurrences of the letter a.+
- The plus sign matches one or more occurrences of the preceding character or group. For example,a+
matches one or more occurrences of the letter a.?
- The question mark matches zero or one occurrence of the preceding character or group. For example,a?
matches zero or one occurrence of the letter a.()
- Parentheses are used to create a capturing group, which captures the matched substring for later reference. For example,(abc)
matches the substring abc and captures it in a group.|
- The vertical bar is used to create a logical OR between two subpatterns. For example,a|b
matches either the letter a or the letter b.
These are just a few of the common matching symbols used in regular expressions in Java. There are many more, and you can combine them in various ways to create powerful regular expressions that match very specific patterns in input strings.