how to handle repetitive regexp match checks

2005-03-17 Thread Matt Wette
Over the last few years I have converted from Perl and Scheme to Python. There one task that I do often that is really slick in Perl but escapes me in Python. I read in a text line from a file and check it against several regular expressions and do something once I find a match. For example, in p

Re: how to handle repetitive regexp match checks

2005-03-17 Thread David M. Cooke
Matt Wette <[EMAIL PROTECTED]> writes: > Over the last few years I have converted from Perl and Scheme to > Python. There one task that I do often that is really slick in Perl > but escapes me in Python. I read in a text line from a file and check > it against several regular expressions and do

Re: how to handle repetitive regexp match checks

2005-03-18 Thread Duncan Booth
Matt Wette wrote: > I am having difficulty doing this cleanly in python. Can anyone help? > > rx1 = re.compile(r'struct {') > rx2 = re.compile(r'typedef struct {') > rx3 = re.compile(r'something else') > > m = rx1.match(line) > if m: >do something > else: >

Re: how to handle repetitive regexp match checks

2005-03-18 Thread Jonathan Giddy
GiddyJP wrote: # do this once import Trespass pattern = Trespass.Pattern() pattern.addRegExp(r'struct {', 1) pattern.addRegExp(r'typedef struct {', 2) pattern.addRegExp(r'something else', 3) Minor correction... in this module { always needs to be escaped if not indicating a

Re: how to handle repetitive regexp match checks

2005-03-18 Thread GiddyJP
Matt Wette wrote: Over the last few years I have converted from Perl and Scheme to Python. There one task that I do often that is really slick in Perl but escapes me in Python. I read in a text line from a file and check it against several regular expressions and do something once I find a match

Re: how to handle repetitive regexp match checks

2005-03-18 Thread Paul McGuire
Matt - Pyparsing may be of interest to you. One of its core features is the ability to associate an action method with a parsing pattern. During parsing, the action is called with the original source string, the location within the string of the match, and the matched tokens. Your code would lo

Re: how to handle repetitive regexp match checks

2005-03-18 Thread Jeff Shannon
Matt Wette wrote: Over the last few years I have converted from Perl and Scheme to Python. There one task that I do often that is really slick in Perl but escapes me in Python. I read in a text line from a file and check it against several regular expressions and do something once I find a match