Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

single quotes not allowing in perl

by vasanthgk91 (Sexton)
on May 24, 2013 at 12:58 UTC ( [id://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 (Canon) 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 (Cardinal) 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (1)
As of 2024-04-25 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found