Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
go ahead... be a heretic
 
PerlMonks  

Perl Regex to take the UC Words.

by Anonymous Monk
on Mar 28, 2013 at 04:14 UTC ( #1025848=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have a doubt on how to take the total UC words out of a line.

Example1:

---------

$string = "BROUGHTON VETERINARY GROUP. Leicestershire mixed practice seeks experienced vet to replace assistant relocating to Scotland";

Here I need to take out the "BROUGHTON VETERINARY GROUP" in a new $string_new.

Example2:

---------

$string = "GIRLING AND BOWDITCH VETERINARY SURGEONS We are looking for an experienced vet for our 5 vet mixed practice.";

Here I need to take out the "GIRLING AND BOWDITCH VETERINARY SURGEONS" in a new $string_new.

Example3:

---------

$string = "STANHOPE PARK VETERINARY HOSPITAL. Due to a pregnancy epidemic we are looking for 2 new vets, 100% small animal hospital in County Durham.";

Here I need to take out the "STANHOPE PARK VETERINARY HOSPITAL" in a new $string_new.

Dear Monks Is it possible using a regex? Kindly help!

Thanks in advance.

Comment on Perl Regex to take the UC Words.
Select or Download Code
Re: Perl Regex to take the UC Words.
by vinoth.ree (Vicar) on Mar 28, 2013 at 04:32 UTC

    Use character class with uppercase letter [A-Z] with word boundary \b

    use strict; use warnings; use Data::Dumper; while(<DATA>) { my @array = $_ =~ m/\b([A-Z]+)\b/g; print "@array\n"; } __DATA__ BROUGHTON VETERINARY GROUP. Leicestershire mixed practice seeks experi +enced vet to replace assistant relocating to Scotland GIRLING AND BOWDITCH VETERINARY SURGEONS We are looking for an experie +nced vet for our 5 vet mixed practice. STANHOPE PARK VETERINARY HOSPITAL. Due to a pregnancy epidemic we are +looking for 2 new vets, 100% small animal hospital in County Durham.

    All is well
      Thx. Vinoth. That was very kind of you. but If there is digits we want to take, how we can do that... means "BROUGHTON VETERINARY GROUP123. Leicestershire456 mixed practice789 seeks experienced000 vet to replace assistant relocating to Scotland" and I want to take "BROUGHTON VETERINARY GROUP123" out of that.

        Try this way,

        use strict; use warnings; use Data::Dumper; while(<DATA>) { my @array = $_ =~ m/\b([A-Z]+(?:\d+)?)\b/g; print "@array\n"; } __DATA__ BROUGHTON VETERINARY GROUP123. Leicestershire mixed practice seeks exp +erienced vet to replace assistant relocating to Scotland GIRLING AND BOWDITCH VETERINARY SURGEONS We are looking for an experie +nced vet for our 5 vet mixed practice. STANHOPE PARK VETERINARY HOSPITAL. Due to a pregnancy epidemic we are +looking for 2 new vets, 100% small animal hospital in County Durham.

        All is well

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1025848]
Approved by vinoth.ree
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-04-21 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (495 votes), past polls