xarray_regex.matcher¶
Matcher object.
Classes
|
Manage a matcher inside the pre-regex. |
-
class
xarray_regex.matcher.
Matcher
(m: re.match, idx: int = 0)¶ Bases:
object
Manage a matcher inside the pre-regex.
- Parameters
m (re.match) – Match object obtained to find matchers in the pre-regex.
idx (int) – Index inside the pre-regex.
-
idx
¶ Index inside the pre-regex.
- Type
int
-
group
¶ Group name.
- Type
str
-
name
¶ Matcher name.
- Type
str
-
custom
¶ If there is a custom regex to use preferentially.
- Type
bool
-
rgx
¶ Regex.
- Type
str
-
discard
¶ If the matcher should not be used when retrieving values from matches.
- Type
bool
-
match
¶ The string that created the matcher %(match).
- Type
str
-
NAME_RGX
= {'B': '[a-zA-Z]*', 'F': '%Y-%m-%d', 'H': '\\d\\d', 'M': '\\d\\d', 'S': '\\d\\d', 'X': '%H%M%S', 'Y': '\\d\\d\\d\\d', 'char': '\\S*', 'd': '\\d\\d', 'idx': '\\d+', 'j': '\\d\\d\\d', 'm': '\\d\\d', 'text': '[a-zA-Z]*', 'x': '%Y%m%d'}¶ Regex str for each type of element.
-
get_regex
() → str¶ Get matcher regex.
Replace the matchers name by regex from Matcher.NAME_RGX. If there is a custom regex, recursively replace ‘%’ followed by a single letter by the corresponding regex from NAME_RGX. ‘%%’ is replaced by a single percentage character.
- Raises
KeyError – Unknown replacement.
-
set_matcher
(m: re.match)¶ Find attributes from match.
- Raises
NameError – No name.
ValueError – Empty custom regex.