Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (13)
As of 2015-07-02 09:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (33 votes), past polls