Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: single quotes not allowing in perl

by Tux (Monsignor)
on May 24, 2013 at 13:06 UTC ( #1035130=note: print w/ replies, xml ) Need Help??

in reply to single quotes not allowing in perl

Why do you escape all those characters inside a character class?

--8<--- use 5.016; use warnings; my $title = "single quotes not allowing in perl"; $title =~ m/^([a-zA-Z0-9 \.\-\(\)\%\&\:\;\,\"\']+)$/ and say "Title matches original re"; $title =~ m/^([-a-zA-Z0-9 .()%&:;,"']+)$/ and say "Title matches simplified re"; -->8--- => Title matches original re Title matches simplified re

Enjoy, Have FUN! H.Merijn

Comment on Re: single quotes not allowing in perl
Download Code
Re^2: single quotes not allowing in perl
by vasanthgk91 (Sexton) on May 24, 2013 at 13:30 UTC

    thank u very much..

    $title value i receiving from param array then i match perl regex condition if the condition satisfies means i will do my work..

    if($title=qr(^([a-zA-Z0-9 -.()%&:;,"'/]+)$)) { print "Do my work"; }

    this is works fine..great thanks

      What do you mean by "receiving from param array"?

      Please show a working, short program (20 lines) that reproduces the problem.

        yeah I use CGI platform..So i receive form datas through param array..

        use CGI; my $cgi=new CGI; my $title=$cgi->param("title");

      Be careful! You have lost the ~ in your match. And you need to place the - at the beginning of the character class. See this example:

      use strict; use warnings; my $title = 'have ++ fun#'; if($title=~qr(^([a-zA-Z0-9 -.()%&:;,"'/]+)$)) { print "Do my work 1\n"; } if($title=~qr(^([-a-zA-Z0-9 .()%&:;,"'/]+)$)) { print "Do my work 2\n"; }

        why use hyphen symbol very beginning..really i don't know that's why i ask u

        Update: Looked again, found the lost tilde in the  $title=qr(...) bit of code, not in the regex expression where I was looking. Nevermind...

        You have lost the ~ in your match.

        I don't see a  '~' (tilde) in the original
            if($title=~/^([a-zA-Z0-9 \.\-\(\)\%\&\:\;\,\"\']+)$/)
        match. Can you clarify how it was lost?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-09-23 02:57 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (210 votes), past polls