What type of problems need regular expressions to solve

Some programmers wonder why they even need to learn regular expressions. Here are some use cases:

  • While searching for some text at times, there are cases where we don't know the value of the text upfront. We just know some rules or patterns of the text. For example, searching for a MAC address in a log message, searching for IP address in a web server access log, or searching for a 10-digit mobile number that may be optionally preceded by 0 or +<2 digit country code>.
  • Sometimes, the length of the text we are trying to extract is unknown, for example, searching URLs that start with http:// or https:// in a CSV file.
  • Sometimes, we need to split a given text on delimiters of a variable ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.