Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regexp problem

Reply
Thread Tools

Regexp problem

 
 
Mark Healey
Guest
Posts: n/a
 
      06-24-2006
Here is the line that is giving me problems:

$Falbum =~ s/$edir\/.\/$Fartist\///;

The problem is that $Fartist sometimes has grouping characters "()[]"
which screws up the search.

How do I get it to treat these characters as if they were "\(\)\[\]"?

--
Mark Healey
marnkews ãt healeyonline döt com

 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      06-24-2006
Mark Healey wrote:
> Here is the line that is giving me problems:
>
> $Falbum =~ s/$edir\/.\/$Fartist\///;
>
> The problem is that $Fartist sometimes has grouping characters "()[]"
> which screws up the search.
>
> How do I get it to treat these characters as if they were "\(\)\[\]"?


perldoc -f quotemeta

jue


 
Reply With Quote
 
 
 
 
Mark Healey
Guest
Posts: n/a
 
      06-25-2006
On Sat, 24 Jun 2006 06:32:29 +0000, Jürgen Exner wrote:

> Mark Healey wrote:
>> Here is the line that is giving me problems:
>>
>> $Falbum =~ s/$edir\/.\/$Fartist\///;
>>
>> The problem is that $Fartist sometimes has grouping characters "()[]"
>> which screws up the search.
>>
>> How do I get it to treat these characters as if they were "\(\)\[\]"?

>
> perldoc -f quotemeta


This doesn't help when I'm using some meta characters in my search
strings. I need something that only does it to the variables.

--
Mark Healey
marnkews ãt healeyonline döt com

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      06-25-2006
Mark Healey wrote:
> On Sat, 24 Jun 2006 06:32:29 +0000, Jürgen Exner wrote:
>>Mark Healey wrote:
>>>
>>>$Falbum =~ s/$edir\/.\/$Fartist\///;
>>>
>>>The problem is that $Fartist sometimes has grouping characters "()[]"
>>>which screws up the search.
>>>
>>>How do I get it to treat these characters as if they were "\(\)\[\]"?

>>
>>perldoc -f quotemeta

>
> This doesn't help when I'm using some meta characters in my search
> strings. I need something that only does it to the variables.


It was a hint that does help if you add some imagination. Following it
up by reading about \Q in "perldoc perlre" would also be useful.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      06-25-2006
Mark Healey wrote:
> On Sat, 24 Jun 2006 06:32:29 +0000, Jürgen Exner wrote:
>
>> Mark Healey wrote:
>>> Here is the line that is giving me problems:
>>>
>>> $Falbum =~ s/$edir\/.\/$Fartist\///;
>>>
>>> The problem is that $Fartist sometimes has grouping characters
>>> "()[]" which screws up the search.
>>>
>>> How do I get it to treat these characters as if they were
>>> "\(\)\[\]"?

>>
>> perldoc -f quotemeta

>
> This doesn't help when I'm using some meta characters in my search
> strings. I need something that only does it to the variables.


Maybe I'm missing something but is there a problem with
$Fartist = quotemeta($Fartist);

jue


 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      06-25-2006
Mark Healey <(E-Mail Removed)> wrote:
> On Sat, 24 Jun 2006 06:32:29 +0000, Jürgen Exner wrote:
>
>> Mark Healey wrote:
>>> Here is the line that is giving me problems:
>>>
>>> $Falbum =~ s/$edir\/.\/$Fartist\///;
>>>
>>> The problem is that $Fartist sometimes has grouping characters "()[]"
>>> which screws up the search.
>>>
>>> How do I get it to treat these characters as if they were "\(\)\[\]"?

>>
>> perldoc -f quotemeta

>
> This doesn't help when I'm using some meta characters in my search
> strings.



Yes it does.


> I need something that only does it to the variables.



quotemeta only does it where you ask it to do it, so ask it to
do it "to the variables":

$edir = quotemeta $edir;
$Fartist = quotemeta $Fartist;
$Falbum =~ s#$edir/./$Fartist/##; # Look Ma! No backslashes!

or, lookup the \Q that the docs mention:

$Falbum =~ s#\Q$edir\E/./\Q$Fartist/##;


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
David Squire
Guest
Posts: n/a
 
      06-25-2006
Jürgen Exner wrote:
> Mark Healey wrote:
>> On Sat, 24 Jun 2006 06:32:29 +0000, Jürgen Exner wrote:
>>
>>> Mark Healey wrote:
>>>> Here is the line that is giving me problems:
>>>>
>>>> $Falbum =~ s/$edir\/.\/$Fartist\///;
>>>>
>>>> The problem is that $Fartist sometimes has grouping characters
>>>> "()[]" which screws up the search.
>>>>
>>>> How do I get it to treat these characters as if they were
>>>> "\(\)\[\]"?
>>> perldoc -f quotemeta

>> This doesn't help when I'm using some meta characters in my search
>> strings. I need something that only does it to the variables.

>
> Maybe I'm missing something but is there a problem with
> $Fartist = quotemeta($Fartist);


Is this a reference to the great Petomane?



DS
 
Reply With Quote
 
Mark Healey
Guest
Posts: n/a
 
      06-26-2006
On Sun, 25 Jun 2006 09:11:15 -0500, Tad McClellan wrote:

> Mark Healey <(E-Mail Removed)> wrote:
>> On Sat, 24 Jun 2006 06:32:29 +0000, Jürgen Exner wrote:
>>
>>> Mark Healey wrote:
>>>> Here is the line that is giving me problems:
>>>>
>>>> $Falbum =~ s/$edir\/.\/$Fartist\///;
>>>>
>>>> The problem is that $Fartist sometimes has grouping characters "()[]"
>>>> which screws up the search.
>>>>
>>>> How do I get it to treat these characters as if they were "\(\)\[\]"?
>>>
>>> perldoc -f quotemeta

>>
>> This doesn't help when I'm using some meta characters in my search
>> strings.

>
>
> Yes it does.
>
>
>> I need something that only does it to the variables.

>
>
> quotemeta only does it where you ask it to do it, so ask it to
> do it "to the variables":
>
> $edir = quotemeta $edir;
> $Fartist = quotemeta $Fartist;
> $Falbum =~ s#$edir/./$Fartist/##; # Look Ma! No backslashes!
>
> or, lookup the \Q that the docs mention:


Like most open source perldoc sucks. By the time you know enough to pick
the right terms to look for you don't need it.

> $Falbum =~ s#\Q$edir\E/./\Q$Fartist/##;


That wasn't on my cheat sheet but I did eventually find it.

--
Mark Healey
marnkews ãt healeyonline döt com

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      06-26-2006
Mark Healey schreef:

> Like most open source perldoc sucks. By the time you know enough to
> pick the right terms to look for you don't need it.


I know I don't need you.

--
Affijn, Ruud

"Gewoon is een tijger."


 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      06-26-2006
Mark Healey <(E-Mail Removed)> wrote:

> Like most open source perldoc sucks.



So long!


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
new RegExp().test() or just RegExp().test() Matìj Cepl Javascript 3 11-24-2009 02:41 PM
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Ruby 1.9 - ArgumentError: incompatible encoding regexp match(US-ASCII regexp with ISO-2022-JP string) Mikel Lindsaar Ruby 0 03-31-2008 10:27 AM
Programmatically turning a Regexp into an anchored Regexp Greg Hurrell Ruby 4 02-14-2007 06:56 PM
RegExp.exec() returns null when there is a match - a JavaScript RegExp bug? Uldis Bojars Javascript 2 12-17-2006 09:59 PM



Advertisments