# Class e.c.p.PatternMatcher(Loggable):

Part of elisa.core.pattern_matcher View In Hierarchy

Known subclasses: elisa.core.pattern_matcher.UriPatternMatcher

Object used to map strings matching regex patterns to python objects.

Line # | Kind | Name | Docs
--- | --- | --- | ---
80 | Method | __init__ | Undocumented
83 | Method | add_pattern | Assign an object to a regex pattern.
96 | Method | remove_pattern | Remove a regex pattern.
114 | Method | match | Match `string` to the list of patterns in the resolver and return the

def __init__(self):
overrides elisa.core.log.Loggable.__init__
Undocumented
def add_pattern(self, regex, obj):
Assign an object to a regex pattern.

Parameters | regex | regular expression (type: `str` )
| obj | the object to assign to strings matching `regex` (type: any python object )

def remove_pattern(self, regex):
Remove a regex pattern.

Parameters | regex | regular expression (type: `str` )
Raises | PatternNotFound | when the pattern is not found

def match(self, string, all=False):

Match `string` to the list of patterns in the resolver and return the associated object.

This tries to match the pattern against the whole string, and not only the beginning of the string as `re.match()` does. Append '.*' to your regular expression if you want the same behaviour as `re`.

Parameters | string | string to match (type: `str` )
| all | whether to return all the matches or only the first one (type: `bool` )
Raises | MatchNotFound | there was no match for the given string