mirror of
https://github.com/Garmelon/PFERD.git
synced 2025-07-13 06:32:32 +02:00
Support named capture groups in regex transformers (#94)
This commit is contained in:
@ -26,6 +26,7 @@ ambiguous situations.
|
|||||||
- Generic `ilias-web` crawler and `ilias-web` CLI command
|
- Generic `ilias-web` crawler and `ilias-web` CLI command
|
||||||
- Support for the course overview page. Using this URL as a target might cause
|
- Support for the course overview page. Using this URL as a target might cause
|
||||||
duplication warnings, as subgroups are listed separately.
|
duplication warnings, as subgroups are listed separately.
|
||||||
|
- Support for named capture groups in regex transforms
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Normalization of meeting names in cards
|
- Normalization of meeting names in cards
|
||||||
|
@ -394,7 +394,8 @@ matches `SOURCE`, the output path is created using `TARGET` as template.
|
|||||||
be referred to as `{g<n>}` (e.g. `{g3}`). `{g0}` refers to the original path.
|
be referred to as `{g<n>}` (e.g. `{g3}`). `{g0}` refers to the original path.
|
||||||
If capturing group *n*'s contents are a valid integer, the integer value is
|
If capturing group *n*'s contents are a valid integer, the integer value is
|
||||||
available as `{i<n>}` (e.g. `{i3}`). If capturing group *n*'s contents are a
|
available as `{i<n>}` (e.g. `{i3}`). If capturing group *n*'s contents are a
|
||||||
valid float, the float value is available as `{f<n>}` (e.g. `{f3}`). If a
|
valid float, the float value is available as `{f<n>}` (e.g. `{f3}`). Named capture
|
||||||
|
groups (e.g. `(?P<name>)`) are available by their name (e.g. `{name}`). If a
|
||||||
capturing group is not present (e.g. when matching the string `cd` with the
|
capturing group is not present (e.g. when matching the string `cd` with the
|
||||||
regex `(ab)?cd`), the corresponding variables are not defined.
|
regex `(ab)?cd`), the corresponding variables are not defined.
|
||||||
|
|
||||||
|
@ -110,6 +110,10 @@ class ExactReTf(Transformation):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
named_groups: Dict[str, str] = match.groupdict()
|
||||||
|
for name, capture in named_groups.items():
|
||||||
|
locals_dir[name] = capture
|
||||||
|
|
||||||
result = eval(f"f{right!r}", {}, locals_dir)
|
result = eval(f"f{right!r}", {}, locals_dir)
|
||||||
return Transformed(PurePath(result))
|
return Transformed(PurePath(result))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user