larray.LGroup.matching

LGroup.matching(deprecated=None, pattern=None, regex=None) LGroup

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

Parameters
patternstr or Group

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

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

>>> from larray import Axis
>>> people = Axis(['Bruce Wayne', 'Bruce Willis', 'Arthur Dent'], 'people')

Let us create a group with all names starting with B

>>> group = people.startingwith('B')
>>> group
people['Bruce Wayne', 'Bruce Willis']

Within that group, all labels containing any characters then W then any characters then s are given by

>>> group.matching(pattern='*W*s')
people['Bruce Willis']

Regular expressions are more powerful but usually harder to write and less readable. For example, here are the labels not containing the letter “i”.

>>> group.matching(regex='^[^i]*$')
people['Bruce Wayne']