[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[py8-std] re

."
|m| m := Python re search: '(?<=abc)def' string: 'abcdef'. ^(m group:0) = #def
|m| m := Python re search: '(?<=-)\w+' string: #spam-egg. ^(m group:0) = #egg

(Python re split: '\W+' string: 'Words, words, words.') = #(Words words words '')
(Python re split: '(\W+)' string: 'Words, words, words.') = #(Words ', ' words ', ' words '.' '')
(Python re split: '\W+' string: 'Words, words, words.' maxsplit: 1) = #(Words 'words, words.')

"(Python re split: '[a-f]+' string: #0a3B9 flags: 2"re.IGNORECASE") = #(#0 #3 #9)

(Python re findall: '\bf[a-z]*' string: 'which foot or hand fell fastest') = #(foot fell fastest)
(Python re findall: '(\w+)=(\d+)' string: 'set width=20 and height=10') = #(#(width #20) #(height #10))

| stream | stream := (Python re sub: 'def\s+([a-zA-Z_][a-zA-Z_0-9]*)\s*\(\s*\):' repl: 'static PyObject*\npy_\1(void)\n{' string: 'def myfunc():') stream. ^(Array with: stream nextLine with: stream nextLine with: stream nextLine) = #('static PyObject*' 'py_myfunc(void)' ${)

"(Python re sub: '-{1,2}' repl: [:m| (String@(Match@m group:0) = $- ifTrue: [$ ] ifFalse: [$-])handle ] string: 'pro----gram-files') = 'pro--gram files'
"Python re sub: '\sAND\s' repl: ' & ' string: 'Baked Beans And Spam' flags: 2"re.IGNORECASE") = 'Baked Beans & Spam'

(Python re escape: 'https://www.python.org') = 'https://www\.python\.org'

| m | m := Python re match: '(\w+) (\w+)' string: 'Isaac Newton, physicist'. ^(Array with: (m group: 0) with: (m group: 1) with: (m group: 2)) = #('Isaac Newton' Isaac Newton)

| m | m := Python re match: '(?P<first_name>\w+) (?P<last_name>\w+)' string: 'Malcolm Reynolds'. ^(m group: 'first_name') = #Malcolm

(Python re match: '(\d+)\.(\d+)' string: '24.1632') groups = #(#24 #1632)

(Python re match: '(?P<first_name>\w+) (?P<last_name>\w+)' string: 'Malcolm Reynolds') groupdict keys sorted = #(first_name last_name)