Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: regex question

by aquarium (Curate)
on Oct 27, 2005 at 14:50 UTC ( [id://503357]=note: print w/replies, xml ) Need Help??


in reply to regex question

you also don't escape characters in a character class. your regex (once g is added for global) will strip back slash characters, as well as braces. i.e. should be:
$var =~ s/[()]//g;
the hardest line to type correctly is: stty erase ^H

Replies are listed 'Best First'.
Re^2: regex question
by Perl Mouse (Chaplain) on Oct 27, 2005 at 15:09 UTC
    you also don't escape characters in a character class. your regex (once g is added for global) will strip back slash characters, as well as braces.
    No, it doesn't. There's no need to escape the parens, but it certainly doesn't do any harm:
    $_ = 'foo\bar(baz)'; print "Before: '$_'; "; s/[\(\)]//g; print "After: '$_'\n"; __END__ Before: 'foo\bar(baz)'; After: 'foo\barbaz'
    No backslashes are removed.
    Perl --((8:>*
Re^2: regex question
by sauoq (Abbot) on Oct 27, 2005 at 22:58 UTC
    you also don't escape characters in a character class.

    That's not very good advice. Sometimes you certainly do need to escape characters in a character class. Take the following for example:

    $ perl -le '$_ = q/f!o@o#b$a%r^b&a*z/; s/[!@#$%^&*]//g; print'

    -sauoq
    "My two cents aren't worth a dime.";
    
      Or, even more drastical, see the difference in these lines:
      perl -e '$_="bjzu-sbtz -abnzo-tbhze-rb zp-ebrzl- bhza-cbkze-r\n";s/[b-z]//g;print'
      vs.
      perl -e '$_="bjzu-sbtz -abnzo-tbhze-rb zp-ebrzl- bhza-cbkze-r\n";s/[b\-z]//g;print'

      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re^2: regex question
by Juerd (Abbot) on Oct 27, 2005 at 19:02 UTC

    the hardest line to type correctly is: stty erase ^H

    Type it as: stty erase ^V^H

    Update: I missed the point, which was that you cannot backspace if backspace isn't set correctly.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://503357]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-26 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found