Skip to main content
iBabs2
Inspiring
February 14, 2018
Answered

I have a GREP to remove the suffixes in file names, but????

  • February 14, 2018
  • 2 replies
  • 689 views

Hello,

I have a simple GREP to find all the suffixes in the document names and remove them, when using Image Catalog script, or dynamic captions etc...... 

\..+

Works great.... Except it there is a . in the name?

So, if I run it on this copy:

babs.world.jpg

babsworld.jpg

Here are my results

babs

babsworld

Second one is fine, first one, no good...so, how do I make sure it only effects the suffix ?

Is that possible? I feel like it is one of the options to search the end of the word?

Regards,

babs

    This topic has been closed for replies.
    Correct answer Jongware

    I assume not all of your suffixes are the same – if they are, just remove all texts ".jpg"...

    To delete everything including and after the final full stop, use this:

    \.[^.]+?$

    i.e., only a full stop where all next characters aren't a full stop. (Not behind my desktop now, so I may be wrong, but without the '?' it may also eat up all hard returns. OTOH I believe the question mark fixes that. Please verify )

    Another option – as file types (which your suffixes seem to be) are usually composed of letters and numbers only, is to eat up only those:

    \.\w+$

    Again, this matches the single full stop, but now it must be followed by a sequence of "word characters", a convenient shortcut for A-Z, digits, and, for some historic reason, the underscore.

    2 replies

    Jongware
    Community Expert
    JongwareCommunity ExpertCorrect answer
    Community Expert
    February 14, 2018

    I assume not all of your suffixes are the same – if they are, just remove all texts ".jpg"...

    To delete everything including and after the final full stop, use this:

    \.[^.]+?$

    i.e., only a full stop where all next characters aren't a full stop. (Not behind my desktop now, so I may be wrong, but without the '?' it may also eat up all hard returns. OTOH I believe the question mark fixes that. Please verify )

    Another option – as file types (which your suffixes seem to be) are usually composed of letters and numbers only, is to eat up only those:

    \.\w+$

    Again, this matches the single full stop, but now it must be followed by a sequence of "word characters", a convenient shortcut for A-Z, digits, and, for some historic reason, the underscore.

    iBabs2
    iBabs2Author
    Inspiring
    February 14, 2018

    Hi Jongware,

    The first option worked fine in a find and change, with many different scenerios.

    Actually both options worked fine in this case.

    NOTE: The hard returns remained intact

    Thank you for the code and explanation.

    Kind Regards,

    Babs

    Community Expert
    February 14, 2018

    Hi Babs,

    if there are suffixes on every file name you are using, you could do this:

    \..{2,4}$

    That means ( from right to left ):
    At the end of a string of characters: $

    look for a character count of 2 to 4: .{2,4}

    where a dot is before: \.

    Regards,

    Uwe

    iBabs2
    iBabs2Author
    Inspiring
    February 14, 2018

    Hello Laubender,

    Thank you, that helps with another one I am working on, but gave me trouble on this particulate find and change GREP option. But that explanation is helping men with something else I may be throwing out there shortly

    Thank you!

    babs