Inserting a Dash Before the First Number in a Filename
Hello,
I have what I thought was a very simple use case, but I can't get the regular expression just right.
I have several file names as such:
Abcd5678.doc
Acd745.doc
Smn6457.doc
The # of letters may vary slightly as may the # of following digits.
I simply want to insert a dash between the last letter and the first digit. So my result would be:
Abcd-5678.doc
Acd-745.doc
Smn-6457.doc
I've played around with some similar examples I found here, but I can't get it right
Any help would be appreciated.
I have what I thought was a very simple use case, but I can't get the regular expression just right.
I have several file names as such:
Abcd5678.doc
Acd745.doc
Smn6457.doc
The # of letters may vary slightly as may the # of following digits.
I simply want to insert a dash between the last letter and the first digit. So my result would be:
Abcd-5678.doc
Acd-745.doc
Smn-6457.doc
I've played around with some similar examples I found here, but I can't get it right
Any help would be appreciated.
Reply to #1:
Hi John,
Sure, no prob. This will do it:
REPLACE method:
To replace: "([a-zA-Z]+)([0-9]+)" <--- WITHOUT QUOTES
Replace with: $1-$2
Occ: All
Case sens.: No
RegExp: YES
Apply to: Name
You are making two containers (denoted by parentheses, and called "capturing groups" in regular expression-ese) that ARen will remember to put into the replacement: The first for the alpha characters and the second for the numeric characters. The square brackets are called "character classes"–they simply define the types, or classes, of characters you are looking for. "a-zA-Z" says you will accept all alpha characters, but ONLY alpha characters. "0-9", of course, accepts numbers. The "+" plus sign after the character classes say match at least one of the character class up to any number. $1 in the replace slot is the first capturing group, etc.
Best regards,
DF
Hi John,
Sure, no prob. This will do it:
REPLACE method:
To replace: "([a-zA-Z]+)([0-9]+)" <--- WITHOUT QUOTES
Replace with: $1-$2
Occ: All
Case sens.: No
RegExp: YES
Apply to: Name
You are making two containers (denoted by parentheses, and called "capturing groups" in regular expression-ese) that ARen will remember to put into the replacement: The first for the alpha characters and the second for the numeric characters. The square brackets are called "character classes"–they simply define the types, or classes, of characters you are looking for. "a-zA-Z" says you will accept all alpha characters, but ONLY alpha characters. "0-9", of course, accepts numbers. The "+" plus sign after the character classes say match at least one of the character class up to any number. $1 in the replace slot is the first capturing group, etc.
Best regards,
DF
Reply to #2:
Thank you!!!
Thank you!!!
Reply to #3:
Heck, if only all the problems were that easy... :)
Best,
DF
Heck, if only all the problems were that easy... :)
Best,
DF