On Wed, Mar 23, 2005 at 05:47:49PM -0800, Andrew P. Lentvorski, Jr. wrote:
> 
> On Mar 23, 2005, at 3:44 PM, Brian Deacon wrote:
> 
> >In the interests of peace, I shall refrain from mentioning the non-Perl
> >language this is implemented in.  :)
> 
> Well, if it's Python then you can use the basic string interpolation 
> stuff to build the string and hand it to re.compile().
> 
> largeMatch = "bigonewithfartoomanycharactersformetobecomfortablewith"
> largeRegex = """(\s*%s\s*)\s+(\s%s\s)*""" % (largeMatch, largeMatch)
> largeRegexCompiled = re.compile(largeRegex)

I had one of those Isaac Newton moments as I was falling asleep last night.  
Or was it Ben Franklin?  The guy who would try to fall asleep while holding 
something in his hand, then when he dropped it and woke up, he'd write down 
whatever he was thinking.  

I think I have it.  Can't check it right now, I'm not in front of the regex 
tools I'm used to.

^(((\s)*crazy(\s)*)(([;\,])|([;\,]?$)))*

The trick is the dollar sign in the middle.  I think this trick won't
work if I need to match across lines, but I never do.

crazy surrounded with any amount of spaces, followed by either a
mandatory delimiter, or an optional delimiter at the end of the line.
All of that repeated as many times as you like.

B

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to