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:

  1. . - The dot metacharacter matches any character except a line break.

  2. [] - 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.

  3. ^ - 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.

  4. $ - The dollar sign matches the end of the input string.

  5. * - 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.

  6. + - 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.

  7. ? - 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.

  8. () - 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.

  9. | - 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.