Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

Comment on single quotes not allowing in perl
Download Code
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?.

Re: single quotes not allowing in perl
by Tux (Monsignor) 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

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

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

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-12-18 04:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls