======== #1 ========

hoge NUM foo
no number here
NUM aaaaaa NUM
---
hoge NUM foo
NUM aaaaaa NUM

======== #2 ========

x.grep('\\w+'):*source.join(',') .. apple,orange,pencil,1234,grape,5678
x.grep('r'):*source.join(',') .. orange,grape
x.grep('^a'):*source.join(',') .. apple
x.grep('^o'):*source.join(',') .. orange
x.grep('pe$'):*source.join(',') .. grape
x.grep('\\d+'):*source.join(',') .. 1234,5678
['1-1', '11-a', '1', '00-', '1-0'].grep('\\d+-\\d+'):*source.join(',') .. 1-1,1-0

======== #3 ========

(0..):*tostring():*match('3').skipnil().head(30):*source.join(',') .. 3,13,23,30,31,32,33,34,35,36,37,38,39,43,53,63,73,83,93,103,113,123,130,131,132,133,134,135,136,137

======== #4 ========

str.sub('(\\w+\\()(\\w+)', & { $m[1] + $m[2].lower() }) .. hoge(abcd, EFGH, IJKL), foo(mnop, QRST), bar(uvwx, 1234)

======== #5 ========

str.match('(\\w+) (\\w+) (\\w+) (\\w+)')[1 .. 4].join() .. abcdefghijklmnopqrstuvwxyz

======== #6 ========

str ..    Ă
re.scan('\\w+', str)::string .. ['', '', '', 'Ă']
re.scan('\\w+', str, 10)::string .. ['', '', 'Ă']
re.scan('\\w+', str, 0, 10)::string .. ['', '']
re.scan('\\w+', str):*group(0)::string .. ['', '', '', 'Ă']
re.scan('\\w+', str, 10):*group(0)::string .. ['', '', 'Ă']
re.scan('\\w+', str, 0, 10):*group(0)::string .. ['', '']

======== #7 ========

str ..    Ă
str.scan('\\w+')::string .. ['', '', '', 'Ă']
str.scan('\\w+', 10)::string .. ['', '', 'Ă']
str.scan('\\w+', 0, 10)::string .. ['', '']
str.scan('\\w+'):*group(0)::string .. ['', '', '', 'Ă']
str.scan('\\w+', 10):*group(0)::string .. ['', '', 'Ă']
str.scan('\\w+', 0, 10):*group(0)::string .. ['', '']

======== #8 ========

str ..    Ă
str.match('\\w+', 0)[0] .. 
str.match('\\w+', 6)[0] .. 
str.match('\\w+', 12)[0] .. 
str.match('\\w+', 12, 13)[0] .. 

======== #9 ========

m.source .. 3.14
m[1] .. 3
m[2] .. 14

======== #10 ========

re.scan('(ba)(.)', 'foobarbazfoobarbaz'):list {|m| [m[0], m[1, 2]] } .. [['bar', ['ba', 'r']], ['baz', ['ba', 'z']], ['bar', ['ba', 'r']], ['baz', ['ba', 'z']]]

======== #11 ========

sourceforge.jp
slashdot.jp
www.google.com

======== #12 ========

['hoge', 'foo', 'bar']
['hoge', 'foo', 'bar']
0
100
300
999
9999

======== #13 ========

['', 'bbbbbb', 'cccccDD', '']
['', 'bbbbbb', 'cccccDD', '']

======== #14 ========

<match:0-2>

======== #15 ========

<match:7-14>
re.match('A(a*)A', 'AA')[1] .. 

======== #16 ========

m.source .. 3.14
m[1] .. 3
m[2] .. 14

======== #17 ========

m.source .. 3.14
m['first'] .. 3
m['second'] .. 14

======== #18 ========

m.source .. 3.14
m['first'] .. 3
m[2] .. 14

======== #19 ========

m.source .. 3.14
m[1] .. 3
m['second'] .. 14

======== #20 ========

cond(re.match('hello', 'HELLO WORLD'), 'match', 'not match') .. not match
cond(re.match(re.pattern('hello'):icase, 'HELLO WORLD'), 'match', 'not match') .. match

======== #21 ========

m.source .. 3.14
m[1] .. 3
m[2] .. 14

======== #22 ========

m.source .. 3.14
m['first'] .. 3
m['second'] .. 14

======== #23 ========

m.source .. 3.14
m['first'] .. 3
m[2] .. 14

======== #24 ========

m.source .. 3.14
m[1] .. 3
m['second'] .. 14

======== #25 ========

cond(re.pattern('hello').match('HELLO WORLD'), 'match', 'not match') .. not match
cond((re.pattern('hello'):icase).match('HELLO WORLD'), 'match', 'not match') .. match

======== #26 ========

68124416 GIBCEEBG
79852197 HJIFCBJH
68230449 GICDAEEJ
92209870 JCCAJIHA
33835830 DDIDFIDA
30807019 DAIAHABJ
63148173 GDBEIBHD
02716246 ACHBGCEG
72034006 HCADEAAG
90312735 JADBCHDF

======== #27 ========

re.sub(',\\s*', ':', '1234, 567,    890,   123') .. 1234:567:890:123
re.sub('def\\s+([a-zA-Z_][a-zA-Z_0-9]*)\\s*\\(\\s*\\):', 'static PyObject*\\npy_\\1(void)\\n{', 'def myfunc():') .. static PyObject*
py_myfunc(void)
{
dashrepl(matchobj) = { if (matchobj[0] == '-') { return(' ') } else { return('-') } }
re.sub('-{1,2}', dashrepl, 'pro----gram-files') .. pro--gram files

======== #28 ========

re.pattern(',\\s*').sub(':', '1234, 567,    890,   123') .. 1234:567:890:123
re.pattern('def\\s+([a-zA-Z_][a-zA-Z_0-9]*)\\s*\\(\\s*\\):').sub('static PyObject*\\npy_\\1(void)\\n{', 'def myfunc():') .. static PyObject*
py_myfunc(void)
{
dashrepl(matchobj) = { if (matchobj[0] == '-') { return(' ') } else { return('-') } }
re.pattern('-{1,2}').sub(dashrepl, 'pro----gram-files') .. pro--gram files

======== #29 ========

 sourceforge.jp slashdot.jp www.google.com

======== #30 ========

 sourceforge.jp slashdot.jp www.google.com

======== #31 group test ========

using re.match#group()
12         0-2
345        3-6
6789       7-11
01         12-14
234        15-18
567        19-22
890        23-26
using re.match#groups()
12         0-2
345        3-6
6789       7-11
01         12-14
234        15-18
567        19-22
890        23-26

======== #32 named capturing group ========

12
34
56
12
34
56

======== #33 test of :multiline ========

re.pattern('foo.bar').match('foo\nbar') .. nil
(re.pattern('foo.bar'):multiline).match('foo\nbar') .. <match:0-7>

======== #34 longest/shortest matching ========

str .. <p>hoge</p>
str.match('<.+>')[0] .. <p>hoge</p>
str.match('<.+?>')[0] .. <p>
str.sub('<.+>', '**') .. **
str.sub('<.+?>', '**') .. **hoge**
