Julia regular expressions

Julia has built-in regular expression handling-as do most modern programming languages. There is no need for a using statement, as regular expressions are basic features of strings in Julia.

We could have a small script that verifies whether a string matches a phone number, for example:

ismatch(r"^\([0-9]{3}\)[0-9]{3}-[0-9]{4}$", "(781)244-1212")
ismatch(r"^\([0-9]{3}\)[0-9]{3}-[0-9]{4}$", "-781-244-1212")

When run in Jupyter, we see the following results, that is the first number is conformant to the format and the second is not:

Julia regular expressions

Get Learning Jupyter 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.