Find knowledge base article(s) by searching for keywords in the title e.g. type linux in the search box below
Find knowledge base article(s) by browsing the subject categories of articles
Technology quick references, cheatsheets, user manuals etc.
Shop Online through ShopifyLite
Tutorials on various IT applications.
Search Title    (UL:0 |SS:f)

Scripting >> Python >> Examples >> Regex >> Examples of regex using re module

 

Spliting strings using multiple separators >>> import re
>>> re.split(r"[.?!]", "One sentence. Another one? And the last one!")
['One sentence', ' Another one', ' And the last one', '']
Spliting strings using multiple separators and capturing the separators >>> import re
>>> re.split(r"([.?!])", "One sentence. Another one? And the last one!")
['One sentence', '.', ' Another one', '?', ' And the last one', '!', '']
Searching for specific string to mask it >>> import re
>>> re.sub(r"[\w.%+-]+@[\w.-]+", "[REDACTED]","Received an email for go_nuts95@myexample.com")
'Received an email for [REDACTED]'
Swaping parts of a string >>> import re
>>> re.sub(r"^([\w .-]*), (\w .-]*)$", r" ","Lovelace, Ada")
'Lovelace, Ada'

 

[ © 2008-2021 myfaqbase.com - A property of WPDC Consulting ]