[Tutor] stopping greedy matches

Mike Hall michael.hall at critterpixstudios.com
Thu Mar 17 19:15:18 CET 2005

<applause> Very nice sir. I'm interested in what you're doing here with 
the caret metacharacter. For one thing, why enclose it and the 
whitespace flag within a character class? Does this not traditionally 
mean you want to strip a metacharacter of it's special meaning?

On Mar 16, 2005, at 8:00 PM, Christopher Weimann wrote:

> 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