http://www.perlmonks.org?node_id=1035130


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

Replies are listed 'Best First'.
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

      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"; }

        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?

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

      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");