Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quickening and simplifying regex...

Status
Not open for further replies.

rmayer4

Programmer
Oct 2, 2001
9
CA
hi!

I have these four lines of code in a script:
Code:
$sqry =~ s/'\w*/ /s;
$sqry =~ s/"//g;
$sqry =~ s/\s*//s;
$sqry =~ s/\s*$//;

They are in that sequence, and one right after the other (nothing between any of these four lines). I'm curious if it's possible to make this into just one line, so it doesn't have to process $sqry four times. Any ideas?
 
Actually, it's usually faster to run multible small regex commands than one big one.
 
oh, okay, thanks alot!

does anyone know how to do this anyway, just so I know? I'm trying to learn reg exps... slow process...
 
I don't think it's feasible to do so, for the following reasons:

1. The first replaces with space, the others with null.

2. One uses the g flag, the others don't.

3. Two use the s flag, the others don't.

However, there are times when you can combine regex's using the OR operator, like this:
Code:
$pets =~ s/cat|dog|ferret|hamster/mammal/g;
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top