Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Regular Expression Help, ABFR9

Hi I need help with the following please.


I'm using A better Finder Rename and I have a long filename.

I need to keep the first 6 characters of the filename and remove everything after it until the last _ and then replace that with a space?


For example


ABCDEFGHIJKLMNOPQRSTUVWXYX_Hello there.jpg


Should become

ABCDEF Hello there.


Hope someone can help


Many Thanks

Matt

iMac, OS X Mavericks (10.9.4)

Posted on Sep 2, 2015 7:50 AM

Reply
5 replies

Sep 2, 2015 1:20 PM in response to MattJayC

The Better Finder Rename tool appears to be following the Perl PCRE regular expression syntax. Since I do not have the Better Finder Rename tool, I cannot test further here.


Here is a link to their Regular Expression manual for A Better Finder Rename Tool. They indicate that they are following the Perl PCRE syntax. Here is the Perldoc Regular Expression documentation. Here is a visual regex tool. Select PCRE as your flavor in this online tool.


Try just this part of the Perl RE:


'/^(......).+_(.+\.)/\1 \2/p'

Sep 3, 2015 11:58 AM in response to MattJayC

Hello


Given input:


ABCDEFGHIJKLMNOPQRSTUVWXYX_Hello there.jpg



do you really want a) string with period at end but extension:


ABCDEF Hello there.



or b) string without peroid and extension:


ABCDEF Hello there



or c) string with extension:


ABCDEF Hello there.jpg



?



According to the following page regarding regular expression in A Better Finder Rename 7:


http://www.publicspace.net/ABetterFinderRename/Manual_RegularExpressionsPrimer.h tml


find and replace expressions below would work:



For a),


matching regular expression:


^(......).*_(.+?)(?:(\.)([^.]+)|$)


substitution expression:


\1 \2\3



For b),


matching regular expression:


^(......).*_(.+?)(?:\.[^.]+|$)


substitution expression:


\1 \2



For c),


matching regular expression:


^(......).*_(.+)


substitution expression:


\1 \2




* Matching patterns are tested to work with Perl but not with A Better Finder Rename, for I don't use the latter.


Hope this may help,

H

Regular Expression Help, ABFR9

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.