|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Regular expression for this?
What is the regular expression to get a format of (\S+ \S+) which add together no more then 25 characters?
|
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Quote:
This is the correct way of doing it. |
|
#4
|
|||
|
|||
|
Quote:
That's the sanest thing I've heard about regexes in a long while. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Regular expression for this? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|