search()#
relationalai.std.re.Pattern
#Pattern.search(string: str|Producer, pos: int|Producer = 0) -> Match
Filters strings that contain a regular expression match and returns a Match
object.
Similar to the search()
function, but also accepts an optional pos
parameter to specify the starting position of the search.
Must be used in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
string | str or Producer | The string to search. |
pos | int or Producer | The starting position of the search. (Default: 0 ). |
Returns#
A Match
object.
Example#
#import relationalai as rai
from relationalai.std import alias, re
# =====
# SETUP
# =====
model = rai.Model("companies")
Company = model.Type("Company")
with model.rule():
Company.add(name="RelationalAI")
Company.add(name="Snowflake")
# =======
# EXAMPLE
# =======
pattern = re.compile(r"AI")
with model.query() as select:
company = Company()
# Filter companies whose name contains 'AI'.
pattern.search(company.name)
response = select(company.name)
print(response.results)
# name
# 0 RelationalAI
Note that raw strings are recommended for regular expressions to avoid issues with backslashes.