re#

relationalai.std

The relationalai.std.re module contains functions and classes for working with regular expressions. It is an analog to the Python re module that works with RAI string values.

NOTE

The actual values of properties and other data in a RAI model are only determined during query evaluation in the RAI Native App. As a result, the Python interpreter can’t access the types or values of data in the model, which means string data can’t be represented as Python str objects.

To import the re module, include the following at the top of your Python file or notebook:

#from relationalai.std import re

Table Of Contents#

Functions#

FunctionDescriptionReturn Type
compile()Compiles a regular expression pattern into a Pattern object.Pattern
escape()Escapes special characters in a string.Expression
search()Searches for a match anywhere in a string.Match
match()Matches a string from the beginning.Match
fullmatch()Matches a string to a regular expression exactly.Match
findall()Finds all matches in a string.tuple[Expression]
sub()Replaces all matches in a string.Expression

Match Objects#

When you call a function like search(), match(), or fullmatch(), it returns a Match object that represents the result of the operation. Match objects provide several attributes and methods for working with the matched string.

Attributes#

NameDescriptionType
.posThe value of pos passed to match(), search(), or fullmatch(). This represents the starting position of the match or search.Producer or Python int
.reThe compiled regular expression object whose .match(), .search(), or .fullmatch() method returned this Match object.Pattern
.stringThe string passed to match(), search(), or fullmatch().Producer or Python str

Methods#

NameDescriptionReturn Type
.group()Returns a subgroup of the match.Expression
.__getitem__()Identical to .group(). Allows subscript access to individual groups from a match.Expression
.start()Returns the starting position of the match.Expression
.end()Returns the ending position of the match.Expression
.span()Returns a tuple containing the starting and ending positions of the match.tuple[Expression]

Pattern Objects#

Pattern objects represents compiled regular expressions and are created using the compile() function. You can use Pattern objects to compile a pattern once and reuse it multiple times for regular expression operations.

Attributes#

NameDescriptionType
.patternThe pattern string from which the Pattern object was compiled.Producer or Python str

Methods#

NameDescriptionReturns
.search()Searches for a match anywhere in a string.Match
.match()Matches a string from the beginning.Match
.fullmatch()Matches a string to a pattern exactly.Match
.findall()Finds all matches in a string.tuple[Expression]
.sub()Replaces all matches in a string.Expression

See Also#