File tree Expand file tree Collapse file tree 2 files changed +72
-0
lines changed
Expand file tree Collapse file tree 2 files changed +72
-0
lines changed Original file line number Diff line number Diff line change 1+ try :
2+ import ure as re
3+ except ImportError :
4+ import re
5+
6+ r = re .compile (".+" )
7+ m = r .match ("abc" )
8+ print (m .group (0 ))
9+ try :
10+ m .group (1 )
11+ except IndexError :
12+ print ("IndexError" )
13+
14+ r = re .compile ("(.+)1" )
15+ m = r .match ("xyz781" )
16+ print (m .group (0 ))
17+ print (m .group (1 ))
18+ try :
19+ m .group (2 )
20+ except IndexError :
21+ print ("IndexError" )
22+
23+
24+ r = re .compile ("o+" )
25+ m = r .search ("foobar" )
26+ print (m .group (0 ))
27+ try :
28+ m .group (1 )
29+ except IndexError :
30+ print ("IndexError" )
31+
32+
33+ m = re .match (".*" , "foo" )
34+ print (m .group (0 ))
35+
36+ m = re .search ("w.r" , "hello world" )
37+ print (m .group (0 ))
Original file line number Diff line number Diff line change 1+ try :
2+ import ure as re
3+ except ImportError :
4+ import re
5+
6+ r = re .compile (" " )
7+ s = r .split ("a b c foobar" )
8+ print (s )
9+
10+ r = re .compile (" +" )
11+ s = r .split ("a b c foobar" )
12+ print (s )
13+
14+ r = re .compile (" +" )
15+ s = r .split ("a b c foobar" , 1 )
16+ print (s )
17+
18+ r = re .compile (" +" )
19+ s = r .split ("a b c foobar" , 2 )
20+ print (s )
21+
22+ r = re .compile (" *" )
23+ s = r .split ("a b c foobar" )
24+ # TODO - no idea how this is supposed to work, per docs, empty match == stop
25+ # splitting, so CPython code apparently does some dirty magic.
26+ #print(s)
27+
28+ r = re .compile ("x*" )
29+ s = r .split ("foo" )
30+ print (s )
31+
32+ r = re .compile ("[a-f]+" )
33+ s = r .split ("0a3b9" )
34+ # TODO - char classes are not yet supported by re1.5
35+ #print(s)
You can’t perform that action at this time.
0 commit comments