Need Help removing characters..

A swapping-ground for Regular Expression syntax

Need Help removing characters..

Postby emusso » Wed Apr 18, 2007 2:43 pm

Hello,

I have a filename that is in this format: 1343-4423-122(Some Text Here).pdf

I want to remove (Some Text Here) out of the filename.

I'm not very good with reg expressions so if someone could help I would very appreciative.

Thanks in advance!!

e
emusso
 
Posts: 5
Joined: Wed Apr 18, 2007 2:22 pm

Postby Admin » Wed Apr 18, 2007 2:47 pm

Hi,

One solution:

MATCH: (.*)(\()(.*)
REPALCE: \1


Jim
Admin
Site Admin
 
Posts: 1483
Joined: Tue Mar 08, 2005 8:39 pm

Thank you thank you

Postby emusso » Wed Apr 18, 2007 2:54 pm

Can I ask you one more favor,

Can you explain each part of that regular expression?
I'm always up for learning more on regular expressions.

Thanks a lot!!!! :D

em
emusso
 
Posts: 5
Joined: Wed Apr 18, 2007 2:22 pm

Postby Admin » Wed Apr 18, 2007 2:58 pm

MATCH: (.*)(\()(.*)

This is broken down into

(.*) - match any number of characters (and call this Group 1)


(\() - match a single open bracket (and call this Group 2)


(.*) - match any number of characters (and call this Group 3)


Then in the REPLACE string I've said that I'm only interested in Group 1.



Jim
Admin
Site Admin
 
Posts: 1483
Joined: Tue Mar 08, 2005 8:39 pm

Postby emusso » Wed Apr 18, 2007 3:06 pm

your awesome!
emusso
 
Posts: 5
Joined: Wed Apr 18, 2007 2:22 pm

Postby jarhtmd » Sun May 27, 2007 7:20 pm

I do this kind of renaming all the time, w/o using regular expressions (which I have never fully understood).

If the original filename structure is 1343-4423-122(Some Text Here).pdf and only the (variable length, I assume) "(Some Text Here)" is to be removed, I simply Remove from 14 to 99 (or some other number larger than the length of the longest text). This leaves the 1st 13 characters and removes everything following.

That's one of the great things that I like about BRU . . . often complex tasks can be accomplished using its simplest features. If I don't understand a feature (like regular expressions), I can most often figure a "work around", even if it means multiple steps. Better to do what I understand than create havoc for myself by making mistakes.
jarhtmd
 
Posts: 33
Joined: Fri Oct 27, 2006 8:53 pm
Location: Maryland, USA


Return to Regular Expressions