Re: [Tutor] stopping greedy matches

2005-03-20 Thread Joerg Woelke
On Fri, Mar 18, 2005 at 12:27:35PM -0500, Christopher Weimann wrote: > So this [^\s]+ means match one or more of any char that > isn't whitespace. Could be just \S+ Greetings, J"o! -- Reply hazy, ask again later. ___ Tutor maillist - Tutor@python

Re: [Tutor] stopping greedy matches

2005-03-19 Thread Christopher Weimann
On 03/17/2005-10:15AM, Mike Hall wrote: > > 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? A caret as the first charachter in a class is a negation. So this [^\s]+ means

Re: [Tutor] stopping greedy matches

2005-03-18 Thread Mike Hall
On Mar 18, 2005, at 1:02 PM, Christopher Weimann wrote: On 03/18/2005-10:35AM, Mike Hall wrote: A caret as the first charachter in a class is a negation. So this [^\s]+ means match one or more of any char that isn't whitespace. Ok, so the context of metas change within a class. That makes sense, bu

Re: [Tutor] stopping greedy matches

2005-03-18 Thread Christopher Weimann
On 03/18/2005-10:35AM, Mike Hall wrote: > > > > A caret as the first charachter in a class is a negation. > > So this [^\s]+ means match one or more of any char that > > isn't whitespace. > > > > Ok, so the context of metas change within a class. That makes sense, > but I'm unclear on th

Re: [Tutor] stopping greedy matches

2005-03-18 Thread Mike Hall
On Mar 18, 2005, at 9:27 AM, Christopher Weimann wrote: On 03/17/2005-10:15AM, Mike Hall wrote: 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? A caret as the first charachte

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Kent Johnson
Mike Hall wrote: On Mar 17, 2005, at 11:11 AM, Kent Johnson wrote: The first one matches the space after 'in'. Without it the .+? will match the single space, then \b matches the *start* of the next word. I think I understand. Basically the first dot advances the pattern forward in order to perf

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
On Mar 17, 2005, at 11:11 AM, Kent Johnson wrote: The first one matches the space after 'in'. Without it the .+? will match the single space, then \b matches the *start* of the next word. I think I understand. Basically the first dot advances the pattern forward in order to perform a non-greedy m

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Kent Johnson
Mike Hall wrote: On Mar 16, 2005, at 8:32 PM, Kent Johnson wrote: "in (.*?)\b" will match against "in " because you use .* which will match an empty string. Try "in (.+?)\b" (or "(?<=\bin)..+?\b" )to require one character after the space. Another working example, excellent. I'm not too clear on

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
I don't have that script on my system, but I may put pythoncard on here and run it through that: http://pythoncard.sourceforge.net/samples/redemo.html Although regexPlor looks like it has the same functionality, so I may just go with that. Thanks. On Mar 17, 2005, at 1:31 AM, Michael Dunn wrote

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
On Mar 16, 2005, at 8:32 PM, Kent Johnson wrote: "in (.*?)\b" will match against "in " because you use .* which will match an empty string. Try "in (.+?)\b" (or "(?<=\bin)..+?\b" )to require one character after the space. Another working example, excellent. I'm not too clear on why the back to

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
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, Christo

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Michael Dunn
As Kent said, redemo.py is a script that you run (e.g. from the command line), rather than something to import into the python interpretor. On my OSX machine it's located in the directory: /Applications/MacPython-2.3/Extras/Tools/scripts Cheers, Michael ___

Re: [Tutor] stopping greedy matches

2005-03-16 Thread Kent Johnson
Mike Hall wrote: Liam, "re.compile("in (.*?)\b")" will not find any match in the example string I provided. I have had little luck with these non-greedy matchers. "in (.*?)\b" will match against "in " because you use .* which will match an empty string. Try "in (.+?)\b" (or "(?<=\bin)..+?\b" )to

Re: [Tutor] stopping greedy matches

2005-03-16 Thread Christopher Weimann
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,

Re: [Tutor] stopping greedy matches

2005-03-16 Thread Mike Hall
On Mar 16, 2005, at 5:32 PM, Sean Perry wrote: I know this does not directly help, but I have never successfully used \b in my regexs. I always end up writing something like foo\s+bar or something more intense. I've had luck with the boundary flag in relation to lookbehinds. For example, if I wa

Re: [Tutor] stopping greedy matches

2005-03-16 Thread Mike Hall
Liam, "re.compile("in (.*?)\b")" will not find any match in the example string I provided. I have had little luck with these non-greedy matchers. I don't appear to have redemo.py on my system (on OSX), as an import returns an error. I will look into finding this module, thanks for pointing me

Re: [Tutor] stopping greedy matches

2005-03-16 Thread Liam Clarke
> >>> x=re.compile(r"(?<=\bin).+\b") Try >>> x = re.compile("in (.*?)\b") .*? is a non-greedy matcher I believe. Are you using python24/tools/scripts/redemo.py? Use that to test regexes. Regards, Liam Clarke On Wed, 16 Mar 2005 12:12:32 -0800, Mike Hall <[EMAIL PROTECTED]> wrote: > I'm hav

[Tutor] stopping greedy matches

2005-03-16 Thread Mike Hall
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" So let's say I want to specify when to begin my pattern by using a lookbehind: >>> x = re.compile