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

Re: Match las word in a sentece

by Anonymous Monk
on Aug 13, 2021 at 15:02 UTC ( [id://11135822]=note: print w/replies, xml ) Need Help??


in reply to Match last word in a sentence

As the previous commenter noted, you have not said what you mean by "word" and "sentence." Assuming a sentence is a bunch of things delimited by white space, you could use /(.+)\s+(.+)/. Because matches are greedy the first capture group grabs everything up to the last delimiter, and the second grabs everything after that.

If your sentences contain line breaks you will want the s qualifier on your regular expression. That is, /(.+)\s+(.+)/s.

If you want to take punctuation into account, that is much more complicated, since the period/full-stop character can also occur internally (say, in "Dr. Jones performs laparoscopy.")

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found