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
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
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
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
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:
>
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
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