Matching specific characters

We use [] square brackets for matching specific characters using regular expressions. We use brackets to find a set of characters. See examples below:

  • [ABC]: Character class representing either A, B, or C.
  • [^ABC]: Character class with negation, any character other than A, B, or C.
  • [0-9]: Any numeric character, either of 0, 1, 28, or 9.
  • [^0-9]: Any character other than 0, 1, 28, or 9.

Get hands-on with 1200+ tech skills courses.