Regexp question...

A

Andrew

I am composing SQL from my perl code.
Using regexp to strip off ||','|| from the end of select query.
Using something like

$select =~ s/\|\|\'\,\'\|\|$//;

Not being regexp virtuoso, would like to ask if it possible to escape
group of characters instead of escaping each one, i.e. something like:

$select =~ s/\||','||$//;

Thanks,
Andrew
 
A

Ala Qumsieh

Andrew said:
I am composing SQL from my perl code.
Using regexp to strip off ||','|| from the end of select query.
Using something like

$select =~ s/\|\|\'\,\'\|\|$//;

You don't need to escape single quotes or commas since they are not
special regexp characters.
Not being regexp virtuoso, would like to ask if it possible to escape
group of characters instead of escaping each one, i.e. something like:

$select =~ s/\||','||$//;

A quick glance into perlre gives you the answer:

$select =~ s/\Q||','||\E$//;

--Ala
 
G

Gunnar Hjalmarsson

Ala said:
A quick glance into perlre gives you the answer:

$select =~ s/\Q||','||\E$//;

Actually, *you* just gave the answer, Ala, without any need for the OP
to look in perldoc perlre. ;-) (To OP: It's a good idea to do so anyway.)

Two further comments:

- \E right before $ is apparently redundant.

- See also perldoc -f quotemeta.
 
H

Henry Law

Highly insufficient parameters.

Andrew, a word of warning if you are new here. Purl Gurl doesn't have
a fine reputation for accuracy in this newsgroup. Do a bit of
Googling in the archives if you want more information, but for the
time being I recommend you don't adopt his/her/its advice without
checking it first.

Henry Law <>< Manchester, England
 
G

gnari

Gunnar Hjalmarsson said:
Okay.. Guess "apparently" was a bad choice of word. ;-) New try:

- \E right before $ is redundant.

you misunderstand. I was not commenting on your wording,
but on your meaning. I am saying you are wrong.
the \E is not redundant.

gnari
 
G

Gunnar Hjalmarsson

gnari said:
you misunderstand. I was not commenting on your wording, but on
your meaning. I am saying you are wrong. the \E is not redundant.

??

Aha, now I understand. Since $ is a pattern metacharacter, \E *is*
needed, or else the pattern would not match without the literal
character $ being included in the string.

My bad. I should know better than questioning an answer to a regex
question without tests.

Thanks, gnari! Sorry for any confusion my comment may have caused.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top