Replacing text from specified starting position....

A swapping-ground for Regular Expression syntax

Replacing text from specified starting position....

Postby ibexcentral » Mon May 04, 2009 6:26 am

Hi,

I want to replace every underscore with a space after the character '@'....for example:

From this:

Text before the at sign@Text_after_the_at_sign.jpg

To this:
Text before the at sign@Text after the at sign.jpg

I am sure this can be done using regular expression or something but I don't know how, can anyone help?

Thanks

Paul
ibexcentral
 
Posts: 4
Joined: Sun Dec 14, 2008 8:43 am

Re: Replacing text from specified starting position....

Postby GMA » Mon May 04, 2009 11:04 pm

Hi, Paul:
Your case is a little harder than it looks:

- If none of your files have underscores before the "@" (or they do but you don't mind them being replaced), you can simply use Repl. (3) to replace all underscores with spaces. But, since you specifically mentioned AFTER the "@", I suppose that's not the case.

- Unless all the files have exactly the same number of underscores after the "@", you can't use one single RegEx to rename them all in one step. So, the only solution I can think of would be the following:

1) Use this in RegEx (1):

MATCH: (.*?@)(.*?)_(.*)
REPLACE: \1\2 \3

2) Select all the files (by pressing CTRL+A or via the "Actions > Select All" menu).

3) Press Rename.

And then repeat steps 2 and 3 until you no longer have any files left to rename. And I DO MEAN repeating step 2; the files may look like they're still selected after you press Rename, but you actually need to select them again to refresh the list.
Cheers,

Gabriel.
GMA
 
Posts: 91
Joined: Sun Dec 02, 2007 1:30 pm
Location: Argentina

Re: Replacing text from specified starting position....

Postby ThanhLoan » Wed Dec 16, 2009 9:04 pm

Hi GMA (Gabriel),
I have a similar challenge that I post in the other thread 'Copy first letter of every word in a file name'
========================================================================
My intial request was for adding abbreviation of songname in a karaoke filename.

Example :
my original karaoke filename :
SunFly116_12-Singer Name-Aname Bname Cname Dname Ename Fname Gname.mkv

I want to rename it to :
SunFly116_12-Singer Name-Aname Bname Cname Dname Ename Fname Gname-ABCDEFG.mkv

This is the RegEx :
(.*)(([A-Z])[a-z]* ([A-Z])[a-z]* ([A-Z])[a-z]* ([A-Z])[a-z]* ([A-Z])[a-z]* ([A-Z])[a-z]* ([A-Z])[a-z]*)
Replace : \1\2-\3\4\5\6\7\8

However, this RegEx only works with a songname of 7 words exactly (Aname to Gname) and I don't know how to make it work for any number of words in the songname.
============================================================================

So there is no way to make RegEx reopeat the function until it hits the end of the string ?

In my situtation, I would need to create one RegEx for each length of the songname ?

Please advise
ThanhLoan
 
Posts: 7
Joined: Fri Dec 11, 2009 8:22 pm


Return to Regular Expressions