TheInfiniteKind / moneydance_open

16 stars 12 forks source link

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

Open onlynone opened 1 year ago

onlynone commented 1 year ago

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:

https://github.com/TheInfiniteKind/moneydance_open/blob/65732cb44e244d7291a3cf6eae9e38ce3db56905/src/com/moneydance/modules/features/findandreplace/ReplaceCommand.java#L401-L406

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 commented 1 year ago

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