Revision [1806]

Last edited on 2011-01-13 23:48:08 by KlenwellAdmin
Additions:
====Split====
===Split on One or More Spaces===
>>> import re
>>> s = 'SAN DIEGO CA 92037 PAGE 2'
>>> re.split('\s+', s)
['SAN', 'DIEGO', 'CA', '92037', 'PAGE', '2']


Revision [1772]

Edited on 2010-12-13 20:43:21 by KlenwellAdmin
Additions:
===Basic alphanum-only example===
> s = 'John!Paul/9{}George'
> re.sub('[^0-9a-zA-Z]', '_', s)
'John_Paul_9__George'
===Replace extra spaces in XML===
Deletions:
Replace extra spaces in XML


Revision [1521]

Edited on 2010-07-20 08:57:11 by KlenwellAdmin
Additions:
return to DevPython


Revision [1520]

Edited on 2010-07-20 08:56:52 by KlenwellAdmin
Additions:
""<tt>re.sub(pattern, repl, string[, count, flags])</tt>"" ([[http://docs.python.org/library/re.html#re.sub docs]])
Deletions:
""<tt>re.sub(pattern, repl, string[, count, flags])</tt>""


Revision [1519]

Edited on 2010-07-20 08:56:13 by KlenwellAdmin
Additions:
====Replace (Sub)====
""<tt>re.sub(pattern, repl, string[, count, flags])</tt>""
Replace extra spaces in XML
re_p = """\s{2,}"""
xml1 = """
<outer>
<inner attr="foo">
some text
</inner>
<outer>
"""
xml2 = re.sub(re_p, ' ', xml1).replace('> <', '><')
print xml2


Revision [1518]

The oldest known version of this page was created on 2010-07-20 08:44:11 by KlenwellAdmin
Valid XHTML 1.0 TransitionalValid CSSWikkaWiki