# Question about regex renaming

**URL:** <https://resource.dopus.com/t/question-about-regex-renaming/2301>\
**Category:** Help & Support\
**Created:** [August 20, 2006, 2:18pm UTC](https://resource.dopus.com/t/question-about-regex-renaming/2301 "2006-08-20T14:18:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![disgust](https://resource.dopus.com/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@disgust](https://resource.dopus.com/u/disgust)\
**Post date:** [August 20, 2006, 2:18pm UTC](https://resource.dopus.com/t/question-about-regex-renaming/2301/1 "2006-08-20T14:18:37Z")

</div>

I'm using the following bit of regex code to do some renaming:

(._)([0-9][0-9])(._)(.mp3)$

basically I want it to strip things like

long\_album\_title\_01\_song\_name.mp3

to

01\_song\_name.mp3

it works however there's one kink. say a file was "long\_album\_title\_01\_007.mp3" or something. this trips it up. basically if there are two numbers in a row after the first occurance it doesn't come out right. how can I make my regex code only look at the FIRST occurance of two numbers in a row?

---

<div class="post-metadata">

**Author:** ![JohnZeman](https://resource.dopus.com/user_avatar/resource.dopus.com/johnzeman/32/26238_2.png) [@JohnZeman](https://resource.dopus.com/u/JohnZeman)\
**Post date:** [August 20, 2006, 3:20pm UTC](https://resource.dopus.com/t/question-about-regex-renaming/2301/2 "2006-08-20T15:20:52Z")

</div>

You might give this a try:

Old name:  
^([^0-9]+)(.\*)

New name:  
\2

The first tagged expression matches anything in the file name from left to right that is not a digit or sequence of digits. The second tagged expression is the remainder of the file name.

---

<div class="post-metadata">

**Author:** ![disgust](https://resource.dopus.com/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@disgust](https://resource.dopus.com/u/disgust)\
**Post date:** [August 31, 2006, 10:16pm UTC](https://resource.dopus.com/t/question-about-regex-renaming/2301/3 "2006-08-31T22:16:38Z")

</div>

the problem with that is that I only want it to match it when there are two (or more) digits in a row. how can I adjust the regex code you gave me do to that?

with ^([^0-9]+)(.\*) I run into the following problem

bgc\_ost\_3\_blow\_up\_01\_victory.mp3

turns into

03\_blow\_up\_01\_victory.mp3

when I want it to be

01\_victory.mp3

---

<div class="post-metadata">

**Author:** ![JohnZeman](https://resource.dopus.com/user_avatar/resource.dopus.com/johnzeman/32/26238_2.png) [@JohnZeman](https://resource.dopus.com/u/JohnZeman)\
**Post date:** [August 31, 2006, 10:58pm UTC](https://resource.dopus.com/t/question-about-regex-renaming/2301/4 "2006-08-31T22:58:22Z")

</div>

Ok, throw out my last offering, let's start over. As long as it's 2 or more consecutive digits you want, you can keep your expression simple like this:

Old name:  
([0-9][0-9].\*)

New name:  
\1

In short the above expression looks for partial file names with two or more consecutive digits and doesn't care what follows them. And when it finds a match, it uses that match as the new name which should fulfill your needs. However just for discussion purposes suppose you wanted two and only two consecutive digits, then the expression becomes more complex:

Old name:  
^0-9

New name:  
\1

This one requires two and only two consecutive digits together. Which can then be followed by anything else.
