from test
.test_support
import verbose
, sortdict
warnings
.filterwarnings("ignore", "the regex module is deprecated",
DeprecationWarning, __name__
)
from regex_syntax
import *
print 'no match:', regex
.match(re
, 'hello aaaabcccc world')
print 'successful search:', regex
.search(re
, 'hello aaaabcccc world')
cre
= regex
.compile('\(' + re
)
print 'caught expected exception'
print 'expected regex.error not raised'
print 'failed awk syntax:', regex
.search('(a+)|(b+)', 'cdb')
prev
= regex
.set_syntax(RE_SYNTAX_AWK
)
print 'successful awk syntax:', regex
.search('(a+)|(b+)', 'cdb')
print 'failed awk syntax:', regex
.search('(a+)|(b+)', 'cdb')
re
= '\(<one>[0-9]+\) *\(<two>[0-9]+\)'
print 'matching with group names and compile()'
print cre
.match('801 999')
print 'caught expected exception'
print 'expected regex.error not raised'
print 'matching with group names and symcomp()'
print cre
.match('801 999')
print cre
.group('one', 'two')
print 'realpat:', cre
.realpat
print 'groupindex:', sortdict(cre
.groupindex
)
print 'not case folded search:', cre
.search('HELLO WORLD')
cre
= regex
.compile(re
, regex
.casefold
)
print 'case folded search:', cre
.search('HELLO WORLD')
print '__members__:', cre
.__members
__
print 'translate:', len(cre
.translate
)
print 'givenpat:', cre
.givenpat
print 'match with pos:', cre
.match('hello world', 7)
print 'search with pos:', cre
.search('hello world there world', 7)
print 'bogus group:', cre
.group(0, 1, 3)
print 'no name:', cre
.group('one')
print 'caught expected exception'
print 'expected regex.error not raised'
from regex_tests
import *
if verbose
: print 'Running regex_tests test suite'
pattern
=s
=outcome
=repl
=expected
=None
pattern
, s
, outcome
, repl
, expected
= t
raise ValueError, ('Test tuples should have 3 or 5 fields',t
)
obj
=regex
.compile(pattern
)
if outcome
==SYNTAX_ERROR
: pass # Expected a syntax error
# Regex syntax errors aren't yet reported, so for
# the official test suite they'll be quietly ignored.
#print '=== Syntax error:', t
print '=== Unexpected exception', t
, repr(msg
)
if outcome
==SYNTAX_ERROR
:
# This should have been a syntax error; forget it.
if result
==-1: pass # No match, as expected
else: print '=== Succeeded incorrectly', t
# Matched, as expected, so now we compute the
# result string and compare it to our expected result.
groups
=obj
.group(1,2,3,4,5,6,7,8,9,10)
for i
in range(len(groups
)):
vardict
['g'+str(i
+1)]=str(groups
[i
])
print '=== grouping error', t
, repr(repl
)+' should be '+repr(expected
)
print '=== Failed incorrectly', t