Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Regex Doubt

by 2teez (Priest)
on Nov 12, 2012 at 12:39 UTC ( #1003432=note: print w/replies, xml ) Need Help??


in reply to Regex Doubt

Hi,
Playing around with regex, I came up with this. This is not absolute but it solves this problem, and some others.
Assuming that the locations you want to extract are the names of places after job titles.

use warnings; use strict; while (<DATA>) { chomp; my $str = reverse $_; if ( $str =~ m/((.*?)(\s\-\s)?(.*?))\3/ ) { my $matched_str = scalar reverse $1; $matched_str =~ s/^(-\s?)?//; print $matched_str, $/; } } __DATA__ Part Time - Weekend Receptionist - Barton le Clay - Barton-le-Clay (ne +ar Luton) Part-Time Weekend Day Veterinary Nurse - Milton Keynes Receptionist - Barton-le-Clay (near Luton) Full Time - Veterinary Nurse - Glasgow Referral - Glasgow Full Time - Professional House wife - Umuezebi Family House - New Have +n-Upper-Chime-Enugu ( near 9th Mile ) Full time liar - Glasgow (Australia)
Output:
Barton le Clay - Barton-le-Clay (near Luton)
Milton Keynes
Barton-le-Clay (near Luton)
Glasgow Referral - Glasgow
Umuezebi Family House - New Haven-Upper-Chime-Enugu ( near 9th Mile )
Glasgow (Australia)

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003432]
help
Chatterbox?
[karlgoethebier]: Lanx: <a name="env">$ENV{ KARL}</a> and [href://?node_id= 1001958#env|See] ;-)
[Discipulus]: dabella12 if you dont use <c> code tags</c> no one will ever look at your problem

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2017-06-24 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (558 votes). Check out past polls.