blob: 9d25d92d10f65a247f6491aecc8c2378e1f65d92 [file] [log] [blame]
Guido van Rossum228b8e81997-04-02 06:13:34 +00001from test_support import verbose
2import regex
3from regex_syntax import *
4
5re = 'a+b+c+'
6print 'no match:', regex.match(re, 'hello aaaabcccc world')
7print 'successful search:', regex.search(re, 'hello aaaabcccc world')
8try:
9 cre = regex.compile('\(' + re)
10except regex.error:
11 print 'caught expected exception'
12else:
13 print 'expected regex.error not raised'
14
15print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')
16prev = regex.set_syntax(RE_SYNTAX_AWK)
17print 'successful awk syntax:', regex.search('(a+)|(b+)', 'cdb')
18regex.set_syntax(prev)
19print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')
20
21re = '\(<one>[0-9]+\) *\(<two>[0-9]+\)'
22print 'matching with group names and compile()'
23cre = regex.compile(re)
24print cre.match('801 999')
25try:
26 print cre.group('one')
27except regex.error:
28 print 'caught expected exception'
29else:
30 print 'expected regex.error not raised'
31
32print 'matching with group names and symcomp()'
33cre = regex.symcomp(re)
34print cre.match('801 999')
35print cre.group(0)
36print cre.group('one')
37print cre.group(1, 2)
38print cre.group('one', 'two')
39print 'realpat:', cre.realpat
40print 'groupindex:', cre.groupindex
41
42re = 'world'
43cre = regex.compile(re)
44print 'not case folded search:', cre.search('HELLO WORLD')
45cre = regex.compile(re, regex.casefold)
46print 'case folded search:', cre.search('HELLO WORLD')
47
48print '__members__:', cre.__members__
49print 'regs:', cre.regs
50print 'last:', cre.last
51print 'translate:', `cre.translate`
52print 'givenpat:', cre.givenpat
53
54print 'match with pos:', cre.match('hello world', 7)
55print 'search with pos:', cre.search('hello world there world', 7)
56print 'bogus group:', cre.group(0, 1, 3)
57try:
58 print 'no name:', cre.group('one')
59except regex.error:
60 print 'caught expected exception'
61else:
62 print 'expected regex.error not raised'