Skip to main content

Regular Expressions

Construction

ExampleRemarks
r”<escaped regex syntax>”r”\\w+”Match a word. Note the \ to escape the .
r”“”<unescaped regex syntax>”“”r”“”\w+”“”Match a word. No need to escape \ since inside triple quotes.

Syntax Regular expression constructs are:

Description
\wWord
\WNot a word.
\sSpace.
\SNot a space.
\dDigit.
\DNot a digit.
\tTab.
.Match any character.
<regex>*Match any number of times.
<regex>?Match or not.
<regex>+Match any number of times but at least once.
<regex>{<n>}Repeat n times.
^Begin of line.
$End of line.
[<x>-<y>]Interval from x to y.
<regex> I <regex>Or.

Operations

NOTE: PARSE AS and INTO are often used together as in:

SELECT *
FROM text_file PARSE AS r"""(\w+)\s+(\d+)"""
INTO (first: _1, second: CAST(_2 AS int))

This parses a text_file into an unnamed record with two elements, which is then converted into a named record with field second of type int.