RegEx for "From Character to end of name"

Tips on writing regular expressions for searching the post list

Moderators: Quade, dexter

RegEx for "From Character to end of name"

Postby HerbFeldman » Tue Apr 19, 2005 7:20 pm

I want to use RegEx to pick out portions of a list of folder names for re-naming using a Find&Replace. Each name has extraneous characters at the end.
Example:

Ramma V1 - ABCDEF
Lamma V6 - FGHIJ
Gamma V8 - XYZ

I want to get all characters from the DASH to the end of the name, including the DASH. Can I do this with regular expressions?
User avatar
HerbFeldman
Active Participant
Active Participant
 
Posts: 89
Joined: Wed Jun 19, 2002 2:00 pm

Registered Newsbin User since: 05/05/02

Postby Smite » Tue Apr 19, 2005 9:00 pm

In most RegEx find and replace aps, you could do the following:
(-.*)
Then, \1 would produce the matching portion of the string.

This really has nothing to do with NewsBin RegEx though, since there's no "replace" type functionality...
Please read the FAQ before asking any questions.
If you're new to newsgroups, and the files on them, you can find a very helpful guide here.
User avatar
Smite
Katamari Damacy Addict
 
Posts: 5318
Joined: Sat May 19, 2001 1:54 am
Location: Alberta, Canada

Registered Newsbin User since: 03/27/03

Postby Kiltme » Tue Apr 19, 2005 9:17 pm

Using Flexible Rename (cool and free) http://hp.vector.co.jp/authors/VA014830/english/FlexRena/

The regexp find ".+- " and replace with "" will turn those into

ABCDEF
FGHIJ
XYZ

Which is what I think you were asking to do.

If you really meant "get rid of" instead of "get" the stuff after the " - " The regexp find " -.+" and replace with "" will turn those into

Ramma V1
Lamma V6
Gamma V8

The ".+" is any number of any character in it's regexp implementation.
User avatar
Kiltme
Seasoned User
Seasoned User
 
Posts: 638
Joined: Mon Jan 05, 2004 2:02 am

Registered Newsbin User since: 01/05/04

Postby HerbFeldman » Wed Apr 20, 2005 12:11 am

Smite wrote:In most RegEx find and replace aps, you could do the following:
(-.*)
Then, \1 would produce the matching portion of the string....


Thanks, I'll try it and see if I can get it to work.

Smite wrote:This really has nothing to do with NewsBin RegEx though, since there's no "replace" type functionality...


True. However, the descript.ion file I use to create the file folder names is created by Newsbin, and I guessed that somebody here would be able to help me figure this out... and I was right!
User avatar
HerbFeldman
Active Participant
Active Participant
 
Posts: 89
Joined: Wed Jun 19, 2002 2:00 pm

Registered Newsbin User since: 05/05/02

Postby HerbFeldman » Wed Apr 20, 2005 12:18 am

Kiltme wrote:Using Flexible Rename (cool and free) http://hp.vector.co.jp/authors/VA014830/english/FlexRena/

The regexp find ".+- " and replace with "" will turn those into

<snip>

The ".+" is any number of any character in it's regexp implementation.

I'll try this one as well. Everything I can learn about regex will come in handy sooner or later.

Thanks for the tip about Flexible Rename. There's lots of renamers, but only a few will do folders as well.
User avatar
HerbFeldman
Active Participant
Active Participant
 
Posts: 89
Joined: Wed Jun 19, 2002 2:00 pm

Registered Newsbin User since: 05/05/02

Postby dexter » Wed Apr 20, 2005 7:45 am

In Perl, I'd do s/(.+) (- .+)/$1/ This would take everything up to the space before the dash and return it in $1 built in variable. The "s" specifies substitution so the result would only be the text to the left of the hyphen (except the space). If you want to know what was after the hyphen, look at the $2 built in variable.
User avatar
dexter
Site Admin
Site Admin
 
Posts: 9514
Joined: Fri May 18, 2001 3:50 pm
Location: Northern Virginia, US

Registered Newsbin User since: 10/24/97

Postby Smite » Wed Apr 20, 2005 11:55 pm

For a regex renamer, I highly recomend Shell Renamer, avaliable here:
http://www.codeproject.com/shell/shswapl.asp

It will do directories, but in order to get the option to bring this up, you must also highlight a file, and right-click on the file. After that, you can always deselect the file from the list.
Please read the FAQ before asking any questions.
If you're new to newsgroups, and the files on them, you can find a very helpful guide here.
User avatar
Smite
Katamari Damacy Addict
 
Posts: 5318
Joined: Sat May 19, 2001 1:54 am
Location: Alberta, Canada

Registered Newsbin User since: 03/27/03


Return to Regular Expressions

Who is online

Users browsing this forum: No registered users and 2 guests