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