Perform a regex substitution in the substitute plugin #5357
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This utilises regex substitution in the substitute plugin. The previous approach only used regex to match the pattern, then replaced it with a static string. This change allows more complex substitutions, where the output depends on the input.
Example use case
Say we want to keep only the first artist of a multi-artist credit, as in the following list:
This would previously have required three separate rules, one for each resulting artist. By using a regex substitution, we can get the desired behaviour in a single rule:
(Capture the text until the first
,
&
orand
, then use that capture group as the output)Notes
I've kept the previous behaviour of only applying the first matching rule, but I'm not 100% sure it's the ideal approach.
I can imagine both cases where you want to apply several rules in sequence and cases where you want to stop after the first match.
To Do
docs/
to describe it.)docs/changelog.rst
to the bottom of one of the lists near the top of the document.)