regular expression reverse match?

Ron Adam radam2 at tampabay.rr.com
Wed Oct 29 00:47:49 EST 2003


On Tue, 28 Oct 2003 21:19:56 -0600, Jay Dorsey <jay at jaydorsey.com>
wrote:

>
>How about:
>
> >>> matcher = "abcd and a bunch of other stuff"
> >>> phrases = ["a", "ab", "abc", "abd", "aaaa", "abcd and a bunch of 
>other stuff and then some"]
> >>> for phrase in phrases:
>... 	if phrase == matcher[:len(phrase)]: print "pass"
>...	else: print "fail"
>...
>pass
>pass
>pass
>fail
>fail
>fail
>
>
>Jay
>

Hi Jay,   That was an overly simple example I gave I think.   The
'pattern' will in most case not be just a simple string.  And I'll
only be testing on one string at a time as it forms.   

It's an interactive input routine.  So as the person types, I want to
test the buffer and accept or reject each key according to the
pattern.  Pass or fail.


This method would work  though if it's possible to expand a regular
expression out to a string of single matching re characters I think.
Then it would be a matter of doing re.match('ibuffer',
pattern[:len(ibuffer)]. 

I just don't know enough yet,  but am learning quickly though,
thanks.

_Ron







More information about the Python-list mailing list