regex
Functions:
| Name | Description |
|---|---|
patterns_to_regex |
Convert a list of patterns into a regex pattern for matching |
patterns_to_regex
¶
Convert a list of patterns into a regex pattern for matching nn.Module submodule or parameter names.
As part of the syntax of the patterns
.is treated as a literal period.*is treated as a wildcard that matches any number of characters.- Each pattern is wrapped in
^and$, i.e. they must match strings beginning to end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Iterable[str]
|
A list of patterns to match. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Returns:
| Type | Description |
|---|---|
re.Pattern[str]
|
A regex pattern that matches any |
Examples:
>>> patterns_to_regex(["*"]).match("transformer.wte")
<re.Match object; span=(0, 15), match='transformer.wte'>