Regular Expressions
Regular expressions (regex) are powerful tools for pattern matching and text processing. They are represented as a pattern that consists of a special set of characters to search for in a string
str
.
This page provides syntax for regular expressions in Julia . Each section includes an example to demonstrate the described methods.
Functions
Action | Function |
---|---|
Check if regex matches a string |
|
Capture regex matches |
|
Specify alternative regex |
|
Character Class
Character class specifies a list of characters to match ([...]
where ...
represents the list) or not match ([^...]
)
Character Class |
|
Any lowercase vowel |
|
Any digit |
|
Any lowercase letter |
|
Any uppercase letter |
|
Any digit, lowercase letter, or uppercase letter |
|
Anything except a lowercase vowel |
|
Anything except a digit |
|
Anything except a space |
|
Any character |
|
Any word character (equivalent to |
|
Any non-word character (equivalent to |
|
A digit character (equivalent to |
|
Any non-digit character (equivalent to |
|
Any whitespace character (equivalent to |
|
Any non-whitespace character (equivalent to |
|
Anchors
Anchors are special characters that can be used to match a pattern at a specified position
Anchor | Special Character |
---|---|
Beginning of line |
|
End of line |
|
Beginning of string |
|
End of string |
|
Repetition and Quantifier Characters
Repetition or quantifier characters specify the number of times to match a particular character or set of characters
Repetition | Character |
---|---|
Zero or more times |
|
One or more times |
|
Zero or one time |
|
Exactly n times |
|
n or more times |
|
m or less times |
|
At least n and at most m times |
|
Input:
Output:
Resources
Julia Documentation: Manual - Strings (see Regular Expressions)
Think Julia: Chapter 8 - Strings
Last updated