Skip to content
Discussion options

You must be logged in to vote

No: capture groups from a query regex are not exposed to modify templates. 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:

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 album

Preview 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'

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Orthopoxvirus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants