Skip to content

fix(filters): empty result when capture-group replace does not match - #937

Open
sankalpsthakur wants to merge 1 commit into
obsidianmd:mainfrom
sankalpsthakur:fix/589-replace-empty-group
Open

fix(filters): empty result when capture-group replace does not match#937
sankalpsthakur wants to merge 1 commit into
obsidianmd:mainfrom
sankalpsthakur:fix/589-replace-empty-group

Conversation

@sankalpsthakur

@sankalpsthakur sankalpsthakur commented Aug 10, 2026

Copy link
Copy Markdown

Summary

When replace uses capture groups like $1 and the regex does not match, JS String.replace returns the original string. Template extractors then dump full page text into the field.

If the replacement references groups and there is no match, return empty string instead. Literal replacements (no $n) keep existing no-match behavior.

Validation

Fixes #589

AI disclosure

AI tools helped draft code and this description. I reviewed the change and ran the tests above before submitting.

…atch

When replace uses $1/$2-style group references and the regex does not
match, String.replace previously returned the original input. Clipper
templates that extract a field via groups then expect "" (Fixes obsidianmd#589).

Signed-off-by: Sankalp Thakur <sankalphimself@gmail.com>
@sankalpsthakur
sankalpsthakur force-pushed the fix/589-replace-empty-group branch from d221067 to 4d1cab8 Compare September 4, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Regex - When there is no content in a group the original content should not be passed out

1 participant