Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 3rd, 2008, 08:51 AM
mitya mitya is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 239 mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 10 h 20 m 44 sec
Reputation Power: 42
RegEx hell - help appreciated

Hi all

I'm struggling with a regular expression. I need to match:

1) The name of a place
2) Then any of [.,: -]
3) Then either nothing or a word that is NOT one of the following three words: oblast, region, krai.

So for example it would match:

"Investment into Chelyabinsk is up on 2007"
"...factory in Chelyabinsk."

But not...

"Investment into Chelyabinsk oblast is up on 2007"
"...factory in Chelyabinsk oblast."

I've looked through lots of guides and found all sorts of info on exceptions (^) and alternatives (|) but can't seem to nail it.

Thanks in advance.

Reply With Quote
  #2  
Old November 3rd, 2008, 04:05 PM
OmegaZero OmegaZero is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2007
Posts: 737 OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 22 h 50 m 49 sec
Reputation Power: 928
If you're using a regex language that supports it, a lookahead is the construct you need. In perl that would look something like:
Code:
/Chelyabinsk[.,: -](?!oblast)/


Otherwise you'll probably have to capture the next word and check if it's valid.
__________________
sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

Reply With Quote
  #3  
Old November 11th, 2008, 03:45 AM
mitya mitya is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 239 mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 10 h 20 m 44 sec
Reputation Power: 42
Thanks - but how can I do that in PHP?

Reply With Quote
  #4  
Old November 11th, 2008, 04:58 AM
mitya mitya is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 239 mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level)mitya User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 10 h 20 m 44 sec
Reputation Power: 42
It's OK, I improvised and it works, thanks again.

preg_match("/$placename*+(?! oblast| region| krai| okrug)/i", $text)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > RegEx hell - help appreciated

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap