Using RegEx to remove underscore

Hello,

me again. :slight_smile: Following up on chrillek’s suggestion to learn RegEx I have progressed a lot using the helpful mentioned sites here in the community (esp. Learn Regex: A Beginner's Guide — SitePoint and Regular Expression Tutorial - Learn How to Use Regular Expressions) and checking my work on https://regex101.com.

Now I have come to a blocker and I need some help. I am trying to remove underscores from my file names. There is an Apple Script to replace text which works, but I would love to use RegEx to replace the underscores. The reason is that I can automate this and using the script is tiresome after a while (entering “_” and then " ") for every file.

I tryed several versions:

Regular Expression: _
Change name to:
This worked on the regex101 site but not in DEVONthink

Then I tried several other variants and one option I found was:
Regular Expression: (.)(_)(.)
Change Name to: \1 \3

However, this only changes on underscore and I have to repeat this Smart Rule multiple times.

Does anyone have an idea how I can either run this replacement until no other underscore is found or
does anyone have a better idea?

I read that Applescript could do the trick but I don’t know this language, and unfortunately I am missing the time to learn it, so I am trying with RegEx.
What works is that I can copy the skript from Bluefrog from this post, but I as I do not understand what it does I fear I might corrupt my filenames.

Thank you very much!

1 Like

That won’t work. DT has no “global” flag, so its REs only find the first match, not all of them.

What I’d try:

  • built a smart group that collects all files whose name contains an underscore
  • select all files in this group
  • run the “replace in file name” script on them

REs really are overkill for a simple character replacement.

Or JavaScript. Perhaps you feel more comfortable with that. But it’s not needed in this case either.

Thanks for getting back so quick to me.

Oh my gosh! That is such a simple and elegant solution. Sometimes I am too deep into trying to use something new that I don‘t see the simple solutions - as we say in German: Haven’t seen the forest due to all the trees (literal translation).

I will use this simple solution. Thanks a lot! :grinning:

Not unknown in English:

"Continued proverbial, being found in an anti -popish tract of the
reign of Charles II.

From him who sees no wood for trees
And yet is busie as the bees
From him that’s settled on his lees
And speaketh not without his fees,
Libera nos.

A Letany for S. triers, 1682."

from an expanded 19c edition of Full text of “The proverbs of John Heywood. Being the “Proverbes” of that author printed 1546. Ed., with notes and introduction”

1 Like