Global matching
----------------------------------------------------------------
Regexp='ba[rz]', Opts='g'
last string='foobarbaz'
number of matches = 1
0 - bar
Regexp='ba[rz]', Opts='g'
last string='foobarbaz'
number of matches = 1
0 - baz
Global matching with back-refs
----------------------------------------------------------------
Regexp='(ba[rz])', Opts='g'
last string='foobarbaz'
number of matches = 2
0 - bar
1 - bar
Regexp='(ba[rz])', Opts='g'
last string='foobarbaz'
number of matches = 2
0 - baz
1 - baz
Matching with nested back-refs
----------------------------------------------------------------
Regexp='([\w\.-]+)@((\d+)\.(\d+)\.(\d+)\.(\d+))', Opts=''
last string='matevz.tadel@137.138.170.210'
number of matches = 7
0 - matevz.tadel@137.138.170.210
1 - matevz.tadel
2 - 137.138.170.210
3 - 137
4 - 138
5 - 170
6 - 210
Split
----------------------------------------------------------------
Regexp=':', Opts=''
last string='root:x:0:0:root:/root:/bin/bash'
number of matches = 7
0 - root
1 - x
2 - 0
3 - 0
4 - root
5 - /root
6 - /bin/bash
Split with maxfields=5
----------------------------------------------------------------
Regexp=':', Opts=''
last string='root:x:0:0:root:/root:/bin/bash'
number of matches = 5
0 - root
1 - x
2 - 0
3 - 0
4 - root:/root:/bin/bash
Split with empty elements in the middle and at the end
maxfields=0, so trailing empty elements are dropped
----------------------------------------------------------------
Regexp=':', Opts=''
last string='root::0:0:root:/root::'
number of matches = 6
0 - root
1 -
2 - 0
3 - 0
4 - root
5 - /root
Split with empty elements at the beginning and end
maxfields=-1, so trailing empty elements are kept
----------------------------------------------------------------
Regexp=':', Opts=''
last string=':x:0:0:root::'
number of matches = 7
0 -
1 - x
2 - 0
3 - 0
4 - root
5 -
6 -
Split with no pattern in string
----------------------------------------------------------------
Regexp=':', Opts=''
last string='A dummy line of text.'
number of matches = 1
0 - A dummy line of text.
Split with regexp potentially matching a null string
----------------------------------------------------------------
Regexp=' *', Opts=''
last string='hi there'
number of matches = 7
0 - h
1 - i
2 - t
3 - h
4 - e
5 - r
6 - e
Split on patteren with back-refs
----------------------------------------------------------------
Regexp='([,-])', Opts=''
last string='1-10,20'
number of matches = 5
0 - 1
1 - -
2 - 10
3 - ,
4 - 20
Substitute
----------------------------------------------------------------
Regexp='(\d+)\.(\d+)\.(\d+)\.(\d+)', Opts=''
Substitute '137.138.170.210','$4.$3.$2.$1' => '210.170.138.137'
Global substitute
----------------------------------------------------------------
Regexp='(\w+)\.(\w+)@[\w\.-]+', Opts='g'
Substitute 'rene.brun@cern.ch, philippe.canal@fnal.gov, fons.rademakers@cern.ch','\u$1 \U$2\E' => 'Rene BRUN, Philippe CANAL, Fons RADEMAKERS'