diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2003-04-24 17:22:04 (GMT) |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2003-04-24 17:22:04 (GMT) |
commit | 9b12d9d0d24550c866fa9c600efe8024f4681fa4 (patch) | |
tree | 316b6930bb4e8fedc0b344af923504ca81967a78 /Demo | |
parent | b7878d09e5d360da4eda65cdf6f51376c234af3d (diff) | |
download | cpython-9b12d9d0d24550c866fa9c600efe8024f4681fa4.zip cpython-9b12d9d0d24550c866fa9c600efe8024f4681fa4.tar.gz cpython-9b12d9d0d24550c866fa9c600efe8024f4681fa4.tar.bz2 |
Modernize the code a bit:
use re module
make chomp() use rstrip()
Diffstat (limited to 'Demo')
-rwxr-xr-x | Demo/comparisons/regextest.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/Demo/comparisons/regextest.py b/Demo/comparisons/regextest.py index e4e18d6..fbc5f6c 100755 --- a/Demo/comparisons/regextest.py +++ b/Demo/comparisons/regextest.py @@ -18,15 +18,12 @@ import string import sys -import regex -from regex_syntax import * - -regex.set_syntax(RE_SYNTAX_EGREP) +import re def main(): pats = map(chomp, sys.stdin.readlines()) - bigpat = '(' + string.joinfields(pats, '|') + ')' - prog = regex.compile(bigpat) + bigpat = '(' + '|'.join(pats) + ')' + prog = re.compile(bigpat) for file in sys.argv[1:]: try: @@ -40,11 +37,10 @@ def main(): if not line: break lineno = lineno + 1 - if prog.search(line) >= 0: + if prog.search(line): print "%s:%s:%s" % (file, lineno, line), def chomp(s): - if s[-1:] == '\n': return s[:-1] - else: return s + return s.rstrip('\n') main() |