larray.Axis.matching

Axis.matching(deprecated=None, pattern=None, regex=None) LGroup[source]

Return a group with all the labels matching the specified pattern or regular expression.

Parameters
patternstr or Group, optional

Pattern to match. * ? matches any single character * * matches any number of characters * [seq] matches any character in seq * [!seq] matches any character not in seq

To match any of the special characters above, wrap the character in brackets. For example, [?] matches the character ?.

regexstr or Group, optional

Regular expression pattern to match. Regular expressions are more powerful than what the simple patterns supported by the pattern argument but are also more complex to write. See Regular Expression for more details about how to build a regular expression pattern.

Returns
LGroup

Group containing all the labels matching the pattern.

Examples

>>> people = Axis(['Bruce Wayne', 'Bruce Willis', 'Waldo', 'Arthur Dent', 'Harvey Dent'], 'people')
>>> # All labels starting with "A" and ending with "t"
>>> people.matching(pattern='A*t')
people['Arthur Dent']
>>> # All labels containing "W" and ending with "s"
>>> people.matching(pattern='*W*s')
people['Bruce Willis']
>>> # All labels with exactly 5 characters
>>> people.matching(pattern='?????')
people['Waldo']
>>> # All labels starting with either "A" or "B"
>>> people.matching(pattern='[AB]*')
people['Bruce Wayne', 'Bruce Willis', 'Arthur Dent']

Regular expressions are more powerful but usually harder to write and less readable

>>> # All labels starting with "W" and ending with "o"
>>> people.matching(regex='A.*t')
people['Arthur Dent']
>>> # All labels not containing character "a"
>>> people.matching(regex='^[^a]*$')
people['Bruce Willis', 'Arthur Dent']