Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: difference in regex

by anonymized user 468275 (Curate)
on May 30, 2018 at 10:46 UTC ( [id://1215441]=note: print w/replies, xml ) Need Help??


in reply to difference in regex

There is a syntax difference between the two because there is a syntax difference between the two. If you mean "why is there a difference in result", I would say that the first returns the result of the expression in round brackets, which is the last match, whereas the second, having no () returns whether or not a match was found. The second also performs substitution, unlike the first. To get a,b,c,d you simply want to place ^(.*) ahead of the ending match to trap it ... I am dropping the s/ in this suggestion because it is a side effect so far not justified in the OP. Also I tend to escape punctuation because it might have special meaning, so ...
my ($val) = ($row =~ /^(.*)\,[^\,]*$/);
(untested)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-03-28 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found