Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find and Replace should allow replacing with regex capture expressions #91

Open
onlynone opened this issue Feb 20, 2023 · 1 comment
Open

Comments

@onlynone
Copy link

onlynone commented Feb 20, 2023

A bunch of my transactions have been imported with a "Description" like: Check #1234 and "Memo" like: Check #1234 USD special other Transfer:Withdrawal:Check, but with no actual check number in the "Check#" field. I thought the Find and Replace extension might have been able to help, but it seems like I can only replace the check field with a static value (i.e. the same one for each matched transaction).

I'd like to use the regex: =^Check #([0-9]+).*$ in the "Free Text" field on the "Find" side, and then use something like $1 in the "Check#" field in the "Replace" side.

It looks like if one uses the "Found text only" checkbox, then indeed the code does:

Matcher result = _findPattern.matcher(originalText);
if (result.find())
{
return result.replaceAll(replacementText);
}
return originalText;

and so one would be able to use captured groups in the replacement text. However, the originalText referenced there is the original text of the field being replaced (the "Check#" in my case), not the field that originally matched the pattern being used (the "Description" or "Memo" field in my case). Since all my check fields are currently empty, they'll never match the regex used to match the transaction.

Would it be possible to use the Matcher object that successfully matched the original transaction as the one used for the replaceAll call?

@yogi1967
Copy link
Collaborator

Sounds like you're proficient at some level with scripting? Why not do this with a little Python script?

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

No branches or pull requests

2 participants