[Tutor] stopping greedy matches

Christopher Weimann csw at k12hq.com
Thu Mar 17 05:00:29 CET 2005


On 03/16/2005-12:12PM, Mike Hall wrote:
> I'm having trouble getting re to stop matching after it's consumed 
> what I want it to.  Using this string as an example, the goal is to 
> match "CAPS": 
> 
> >>> s = "only the word in CAPS should be matched" 
> 

jet% python
Python 2.4 (#2, Jan  5 2005, 15:59:52)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> s = "only the word in CAPS should be matched"
>>> x=re.compile(r"\bin ([^\s]+)")
>>> x.findall(s)
['CAPS']
>>>



More information about the Tutor mailing list