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

Re: minimal matching to end of string in regular expressions

by JavaFan (Canon)
on Mar 04, 2012 at 11:43 UTC ( [id://957765]=note: print w/replies, xml ) Need Help??


in reply to minimal matching to end of string in regular expressions

In general, if you want to find the last pattern in a string:
/.*PAT/s;
So, in your case:
s/(.*)\).*/$1/s;
You can also combine this with the \K construct:
s/.*\K\).*//s
BTW, your question makes it unclear to me whether you want to trailing newline to be removed. My code does, and your "want it to be" does not include a newline -- but your original solution does.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-24 10:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found