[ create a new paste ] login | about

Link: http://codepad.org/SFjk5YzF    [ raw code | output | fork ]

Python, pasted on Feb 26:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import re
exp = re.compile(r'tu(m*)y')
s='''scratch your tummy'''

## Does the full string match?
match_obj = exp.match(s)
print match_obj
print 'The above should be None.'

## Does any of the string match?
match_obj = exp.search(s)
print match_obj
print "Ooh! It is some non-None value."

print match_obj.group(0)
print "The above shows the part that matched, on the whole."

print match_obj.group(1)
print 'The above shows the 1st "captured" group (which is any number of m characters)'


Output:
1
2
3
4
5
6
7
8
None
The above should be None.
<_sre.SRE_Match object at 0x4034abe0>
Ooh! It is some non-None value.
tummy
The above shows the part that matched, on the whole.
mm
The above shows the 1st "captured" group (which is any number of m characters)


Create a new paste based on this one


Comments: