Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

single quotes not allowing in perl

by vasanthgk91 (Sexton)
on May 24, 2013 at 12:58 UTC ( #1035126=perlquestion: print w/replies, xml ) Need Help??
vasanthgk91 has asked for the wisdom of the Perl Monks concerning the following question:

single quotes not allowing my regular expression condition

if($title=~/^([a-zA-Z0-9 \.\-\(\)\%\&\:\;\,\"\']+)$/)

single quotes coming from this title..Not match this condition

Replies are listed 'Best First'.
Re: single quotes not allowing in perl
by Tux (Abbot) on May 24, 2013 at 13:06 UTC

    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

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

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

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

Re: single quotes not allowing in perl
by marto (Bishop) on May 24, 2013 at 13:03 UTC

    Is there a reason you're not showing us the data? Is the value of $title a secret? What do you expect this regex to do? What is the desired output? Once again please read and understand How do I post a question effectively?.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1035126]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2017-06-29 04:59 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (653 votes). Check out past polls.