Skip to content

Overview

Extended Pattern Matching.

Functions:

Name Description
is_pattern

Return True if pattern contains * or ?.

match

Return True if name matches pattern.

matchs

Return True if name matches element of patterns.

matchsp

Return matching pattern if name matches element of patterns.

Attributes:

Name Type Description
matches

Alias to matchs.

matchespat

Alias to matchsp.

matches module-attribute

matches = matchs

Alias to matchs.

matchespat module-attribute

matchespat = matchsp

Alias to matchsp.

is_pattern

is_pattern(pattern)

Return True if pattern contains * or ?.

match

match(name, pattern)

Return True if name matches pattern.

Pattern may contain * and ?. * matches any characters, ? matches exactly one character.

>>> match('foo', 'foo')
True
>>> match('foo', '*')
True
>>> match('foo', 'bar*')
False
>>> match('foo', 'fo?')
True

matchs

matchs(name, patterns)

Return True if name matches element of patterns.

Pattern may contain * and ?. * matches any characters, ? matches exactly one character.

>>> matchs('foo', ['foo', 'bar'])
True
>>> matchs('foo', ['*'])
True
>>> matchs('foo', ['bar*', 'baz'])
False
>>> matchs('ba', ['bar*', 'baz'])
False
>>> matchs('baz', ['bar*', 'baz'])
True
>>> matchs('baz2', ['bar*', 'baz'])
False

matches is an alias to matchs

>>> matches('foo', ['foo', 'bar'])
True

matchsp

matchsp(name, patterns)

Return matching pattern if name matches element of patterns.

Pattern may contain * and ?. * matches any characters, ? matches exactly one character.

>>> matchsp('foo', ['foo', 'bar'])
'foo'
>>> matchsp('foo', ['*'])
'*'
>>> matchsp('foo', ['bar*', 'baz'])
>>> matchsp('ba', ['bar*', 'baz'])
>>> matchsp('baz', ['bar*', 'baz'])
'baz'
>>> matchsp('baz2', ['bar*', 'baz'])

matchespat is an alias to matchsp

>>> matchespat('foo', ['foo', 'bar'])
'foo'