The basic rules of regular expressions

Many of you are familiar with wild cards (in the Unix world, it is called glob pattern) matching of text. Here:

  • ? matches any single character
  • * matches any sequence of characters
  • [abc] matches any one character inside square brackets, so it will match a, b, or c

The regular expression pattern goes many steps farther than wild cards, where one can set many rules in a regex pattern, such as the following:

  • Match a character or a group of characters optionally (0 or 1 times)
  • Use quantifiers in regex patterns to match variable length text
  • Use a character class to match one of the listed characters or match a range of characters
  • Use a negated character class to match any character except those matched ...

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.