Regexp problem

Discussion in 'Perl Misc' started by Mark Healey, Jun 24, 2006.

  1. Mark Healey

    Mark Healey Guest

    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
    Mark Healey, Jun 24, 2006
    #1
    1. Advertising

  2. 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
    Jürgen Exner, Jun 24, 2006
    #2
    1. Advertising

  3. Mark Healey

    Mark Healey Guest

    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
    Mark Healey, Jun 25, 2006
    #3
  4. 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
    Gunnar Hjalmarsson, Jun 25, 2006
    #4
  5. 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
    Jürgen Exner, Jun 25, 2006
    #5
  6. 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.



    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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jun 25, 2006
    #6
  7. Mark Healey

    David Squire Guest

    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
    David Squire, Jun 25, 2006
    #7
  8. Mark Healey

    Mark Healey Guest

    On Sun, 25 Jun 2006 09:11:15 -0500, Tad McClellan 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.

    >
    >
    > 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
    Mark Healey, Jun 26, 2006
    #8
  9. Mark Healey

    Dr.Ruud Guest

    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."
    Dr.Ruud, Jun 26, 2006
    #9
  10. Mark Healey <> wrote:

    > Like most open source perldoc sucks.



    So long!


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jun 26, 2006
    #10
  11. Tad McClellan <> wrote in
    news::

    > Mark Healey <> wrote:
    >
    >> Like most open source perldoc sucks.

    >
    >
    > So long!


    Good to know there are some constants in life ;-) Like the infinite supply
    of killfile candidates.

    Sinan

    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Jun 26, 2006
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Hurrell
    Replies:
    4
    Views:
    158
    James Edward Gray II
    Feb 14, 2007
  2. Mikel Lindsaar
    Replies:
    0
    Views:
    482
    Mikel Lindsaar
    Mar 31, 2008
  3. Joao Silva
    Replies:
    16
    Views:
    359
    7stud --
    Aug 21, 2009
  4. Uldis  Bojars
    Replies:
    2
    Views:
    190
    Janwillem Borleffs
    Dec 17, 2006
  5. Matìj Cepl

    new RegExp().test() or just RegExp().test()

    Matìj Cepl, Nov 24, 2009, in forum: Javascript
    Replies:
    3
    Views:
    179
    Matěj Cepl
    Nov 24, 2009
Loading...

Share This Page