Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython 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 May 15th, 2004, 11:19 AM
EeeK EeeK is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 1999
Location: Singapore
Posts: 8 EeeK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 42 sec
Reputation Power: 0
Send a message via ICQ to EeeK
Regular expression for this?

What is the regular expression to get a format of (\S+ \S+) which add together no more then 25 characters?

Reply With Quote
  #2  
Old May 15th, 2004, 01:57 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
If I understand correctly, you want to match on two 'words' of non-whitespace characters, separated by a single space, whose total length is <= 25 characters (including the space).

This is doable in a single regular expression, but not easily. You could do something like:

regex= r'(\S \S{1,23})|(\S{2} \S{1,22})|(\S{3} \S{1,21})|...|(\S{23} \S)'

Where '...' in the above needs to be filled with all the intermediate combinations.

but this would be very cumbersome and probably highly inefficient.

I think it would be better to match on r'\S+ \S+' and then filter out the matches that are too long.

Dave - The Developers' Coach

Reply With Quote
  #3  
Old May 15th, 2004, 02:13 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
Quote:
Originally Posted by DevCoach
I think it would be better to match on r'\S+ \S+' and then filter out the matches that are too long.

This is the correct way of doing it.
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
  #4  
Old May 15th, 2004, 04:39 PM
percivall percivall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 133 percivall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Quote:
Originally Posted by DevCoach
I think it would be better to match on r'\S+ \S+' and then filter out the matches that are too long.

That's the sanest thing I've heard about regexes in a long while.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Regular expression for this?


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT