Use Regex Capture Group in Replacement #6043
|
Hi all, is there a way to use a regex capture groups in the replacement in modify? Example: Edit: I already tested: Cheers |
Replies: 1 comment
|
No: capture groups from a query regex are not exposed to For this transformation, an inline field can perform the regex and return the new value: plugins: inline
album_fields:
episode_album: |
import re
match = re.search(r"/music/some-path/(\d{3})_(.*?)(?:/|$)", path)
return f"Prefix {match.group(1)}: {match.group(2)}" if match else albumPreview it first: beet ls -a -f '$album -> $episode_album' 'path::^/music/some-path/'Then apply it: beet modify -a 'path::^/music/some-path/' 'album=$episode_album'Quoting the assignment is important so the shell does not expand |
No: capture groups from a query regex are not exposed to
modifytemplates. A query only decides whether an item/album matches; the replacement template is then evaluated from model fields, so$1,\1, and\g<1>have no capture context.For this transformation, an inline field can perform the regex and return the new value:
Preview it first:
Then apply it: