Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: regex for string

by saranperl (Initiate)
on Aug 18, 2009 at 09:01 UTC ( [id://789391]=note: print w/replies, xml ) Need Help??


in reply to Re: regex for string
in thread regex for string

ya its working fine thank you. why it is not working to giving like this
$str=~m/^(.?).*(.?)$/

Replies are listed 'Best First'.
Re^3: regex for string
by arkturuz (Curate) on Aug 18, 2009 at 09:36 UTC
    It won't match what you want because the '*' quantifier is greedy, and the '?' can match 0 or 1 times. So, the '*' matches all of the it can, and the last '?' matches 0 times; so the match is successful. You have to force '*' to give something back to the rest of the regex by replacing '?' with '{1}' for example.
      good explaination... thanks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-19 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found