Book Image

Getting Started with Julia

By : Ivo Balbaert
Book Image

Getting Started with Julia

By: Ivo Balbaert

Overview of this book

Table of Contents (19 chapters)
Getting Started with Julia
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The Rationale for Julia
Index

Regular expressions


To search for and match patterns in text and other data, regular expressions are an indispensable tool for the data scientist. Julia adheres to the Perl syntax of regular expressions. For a complete reference, refer to http://www.regular-expressions.info/reference.html. Regular expressions are represented in Julia as a double (or triple) quoted string preceded by r, such as r"..." (optionally, followed by one or more of the i, s, m, or x flags), and they are of type Regex. The chapter 2\regexp.jl script shows some examples.

In the first example, we will match the e-mail addresses (#> shows the result):

email_pattern = r".+@.+"
input = "[email protected]"
println(ismatch(email_pattern, input)) #> true

The regular expression pattern + matches any (non-empty) group of characters. Thus, this pattern matches any string that contains @ somewhere in the middle.

In the second example, we will try to determine whether a credit card number is valid or not:

visa = r"^(?:4[0-9]...