escape()#

relationalai.std.re
#escape(regex: str|Producer) -> Expression

Escapes special characters in a regular expression string. Use this to match an arbitrary string that may contain regular expression metacharacters. Must be used in a rule or query context.

Parameters#

NameTypeDescription
regexstr or ProducerThe string to escape.

Returns#

An Expression object.

Example#

#import relationalai as rai
from relationalai.std import re

# =====
# SETUP
# =====

model = rai.Model("companies")
Company = model.Type("Company")

with model.rule():
    Company.add(name="RelationalAI", url="https://relational.ai")
    Company.add(name="Snowflake", url="https://snowflake.com")


# =======
# EXAMPLE
# =======

# Get the names of companies whose URL contains '.ai'.
with model.query() as select:
    company = Company()
    # Escape the '.' in '.ai' to match a literal '.' character.
    escaped = re.escape(".ai")
    # Filter companies whose URL contains '.ai'.
    re.search(escaped, company.url)
    response = select(company.name)

print(response.results)
#            name
# 0  RelationalAI

See Also#