fullmatch()#

relationalai.std.re.Pattern
#Pattern.fullmatch(string: str|Producer, pos: int|Producer = 0) -> Match

Filters strings if the entire string matches a regular expression and returns a Match object. Similar to the fullmatch() function, but also accepts an optional pos parameter to specify the starting position of the match. Must be used in a rule or query context.

Parameters#

NameTypeDescription
stringstr or ProducerThe string to match against.
posint or ProducerThe starting position of the match. (Default: 0)

Returns#

A Match object.

Example#

#import relationalai as rai
from relationalai.std import re

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

model = rai.Model("people")
Person = model.Type("Person")

with model.rule():
    Person.add(name="Alan Turing")
    Person.add(name="Gottfried Wilhelm Leibniz")


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

pattern = re.compile(r"(\w+) (\w+)")

with model.query() as select:
    person = Person()
    # Filter people whose full name matches the pattern.
    pattern.fullmatch(person.name)
    response = select(person.name)

print(response.results)
#           name
# 0  Alan Turing

Note that raw strings are recommended for regular expressions to avoid issues with backslashes.

See Also#