Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Regexp question...

0 views
Skip to first unread message

Andrew

unread,
May 2, 2004, 1:00:26 PM5/2/04
to
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

Ala Qumsieh

unread,
May 2, 2004, 1:05:21 PM5/2/04
to
Andrew wrote:
> 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

Gunnar Hjalmarsson

unread,
May 2, 2004, 1:19:02 PM5/2/04
to
Ala Qumsieh wrote:

> Andrew wrote:
>> 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$//;

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.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Purl Gurl

unread,
May 2, 2004, 1:52:45 PM5/2/04
to
Andrew wrote:

(snipped)

> Using regexp to strip off ||','|| from the end of select query.

Highly insufficient parameters. You have failed to state
if this case is always true, sometimes true, nor if this case
contains all of those characters, some of those characters,
none of those characters, nor have you stated if your case
ends with a newline. You have also failed to state what
precedes your case example.

Do consider providing clear, concise and coherent parameters
with which a reader may work, sans guessing.


Purl Gurl
--

#!perl

$input = "no parameters set unknown ||','||";

substr ($input, rindex ($input, "||','||"), 7, "");

print $input;


PRINTED RESULTS:
________________

no parameters set unknown

gnari

unread,
May 2, 2004, 2:05:35 PM5/2/04
to
"Gunnar Hjalmarsson" <nor...@gunnar.cc> wrote in message
news:c73b12$hfqig$1...@ID-184292.news.uni-berlin.de...

> Ala Qumsieh wrote:
> >
> > $select =~ s/\Q||','||\E$//;
>
> - \E right before $ is apparently redundant.

apparently not

gnari


Henry Law

unread,
May 2, 2004, 4:46:31 PM5/2/04
to
On Sun, 02 May 2004 10:52:45 -0700, Purl Gurl <purl...@purlgurl.net>
wrote:

>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

Gunnar Hjalmarsson

unread,
May 2, 2004, 5:27:43 PM5/2/04
to
gnari wrote:

> Gunnar Hjalmarsson wrote:
>>Ala Qumsieh wrote:
>>
>>> $select =~ s/\Q||','||\E$//;
>>
>>- \E right before $ is apparently redundant.
>
> apparently not

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

- \E right before $ is redundant.

Purl Gurl

unread,
May 2, 2004, 6:25:58 PM5/2/04
to
Henry Law wrote:

> Purl Gurl wrote:

(context deliberately removed by Law)

> >Highly insufficient parameters.



> Purl Gurl doesn't have a fine reputation for accuracy in this newsgroup.

For the originating author, I suggest, "...providing clear, concise


and coherent parameters with which a reader may work, sans guessing."

You state, "Purl Gurl doesn't have a fine reputation for accuracy
in this newsgroup."

My, you are quite the Queen's git.


Purl Gurl

gnari

unread,
May 2, 2004, 6:42:26 PM5/2/04
to
"Gunnar Hjalmarsson" <nor...@gunnar.cc> wrote in message
news:c73pbp$hc3kj$1...@ID-184292.news.uni-berlin.de...

> gnari wrote:
> > Gunnar Hjalmarsson wrote:
> >>Ala Qumsieh wrote:
> >>
> >>> $select =~ s/\Q||','||\E$//;
> >>
> >>- \E right before $ is apparently redundant.
> >
> > apparently not
>
> 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


Gunnar Hjalmarsson

unread,
May 2, 2004, 7:54:31 PM5/2/04
to
gnari wrote:
> Gunnar Hjalmarsson wrote:
>> gnari wrote:
>>> Gunnar Hjalmarsson wrote:
>>>> Ala Qumsieh wrote:
>>>>>
>>>>> $select =~ s/\Q||','||\E$//;
>>>>
>>>> - \E right before $ is apparently redundant.
>>>
>>> apparently not
>>
>> 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.

??

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.

Mark Clements

unread,
May 2, 2004, 9:08:08 PM5/2/04
to
Purl Gurl wrote:


> My, you are quite the Queen's git.

is that a decimal git, or do we have moronity in town, tediously, and
yet again?

0 new messages