Remove characters followed by sequence regex?

A swapping-ground for Regular Expression syntax

Remove characters followed by sequence regex?

Postby tommy2000 » Sat Jan 16, 2016 1:46 am

Greetings,

As I'm at the point making SWAG's, thought I'd check with the experts here.

I've got a series of file names that I'd like to remove a character string that is immediately followed by a sequence number. So, I'd have this:

Filename to convert: "Test Results01 Lab01.str" "Test Results02 Lab02.str" ...and on to "Test Results50 Lab50". As well I have another set of files that have a similar naming but go to 3 sequence digits, ex: "Test Results101 CLab101.str".

Filenames after conversion: "Test Results XX.str" So, I still have different file names since the XX is also a sequence number.

I've figured out I can use ^(.+)Lab.+$ to remove LabXX, but am left with "Test Results01..str" (an extra "."). I can strip this out, yes with Remove(5).

However, I'm sure there's a regex that would do this without the need to do Remove(5).

It's more of an academic exercise, since I did figure a work-around. But in the interests of pure science... :-)

Any thoughts? Thanks!

Tom
tommy2000
 
Posts: 4
Joined: Sat Jan 16, 2016 1:35 am

Re: Remove characters followed by sequence regex?

Postby Admin » Sat Jan 16, 2016 2:04 am

Hi, what do you use as replace in the RegEx? thanks
Admin
Site Admin
 
Posts: 1505
Joined: Tue Mar 08, 2005 8:39 pm

Re: Remove characters followed by sequence regex?

Postby tommy2000 » Sat Jan 16, 2016 5:55 am

I used /1.

Thanks!
tommy2000
 
Posts: 4
Joined: Sat Jan 16, 2016 1:35 am

Re: Remove characters followed by sequence regex?

Postby tommy2000 » Sat Jan 16, 2016 5:56 am

I meant \1
tommy2000
 
Posts: 4
Joined: Sat Jan 16, 2016 1:35 am

Re: Remove characters followed by sequence regex?

Postby Admin » Sat Jan 16, 2016 7:18 am

I tried

Match: (.+) Lab.+$
Replace: \1

It does not give me the extra .
Do you have the option to ignore file extension "Renaming Options" -> "Ignore"
Admin
Site Admin
 
Posts: 1505
Joined: Tue Mar 08, 2005 8:39 pm

Re: Remove characters followed by sequence regex?

Postby tommy2000 » Sat Jan 16, 2016 3:33 pm

You were right, I realized that this set of files had "xxxx.Lab01.str". There was a "." in front the word "Lab" in some of the directories. I missed that completely. So, the regex you used...and mine too...worked fine.

Cockpit error! :-)

Much appreciated. Thanks!

Tom
tommy2000
 
Posts: 4
Joined: Sat Jan 16, 2016 1:35 am


Return to Regular Expressions