Regexp problem

M

Mark Healey

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 "\(\)\[\]"?
 
J

Jürgen Exner

Mark said:
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
 
M

Mark Healey

Mark said:
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.
 
G

Gunnar Hjalmarsson

Mark said:
Mark said:
$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.
 
J

Jürgen Exner

Mark said:
Mark said:
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
 
T

Tad McClellan

Mark Healey said:
Mark said:
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/##;
 
D

David Squire

Jürgen Exner said:
Mark said:
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
 
M

Mark Healey

Mark Healey said:
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.
 
D

Dr.Ruud

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.
 

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

Similar Threads

Logic Problem with BigInteger Method 2
small regexp help 1
Search Results with Pagination 1
Problem with KMKfw libraries 1
Problem with code 6
regexp 9
Some regexp problems 7
regexp and binary values 5

Members online

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,634
Latest member
RonnyBoelk

Latest Threads

Top