Regular expressions
Regular expressions are used for powerful pattern-matching of substrings within strings. They can be used to search for a substring in a string, based on patterns—and then to extract or replace the matches. Julia provides support for Perl-compatible regular expressions.
The most common way to input regular expressions is by using the so-called nonstandard string literals. These look like regular double-quoted strings, but carry a special prefix. In the case of regular expressions, this prefix is "r"
. The prefix provides for a different behavior, compared to a normal string literal.
For example, in order to define a regular string that matches all the letters, we can use r"[a-zA-Z]*".
Julia provides quite a few nonstandard string literals—and we can even define our own if we want to. The most widely used are for regular expressions (r"..."
), byte array literals (b"..."
), version number literals (v"..."
), and package management commands (pkg"..."
).
Here is how we build a regular...