<div><h2id="regex"><ahref="#regex"name="regex">#</a>Regex</h2><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">import</span> re
<str> = re.sub(<regex>, new, text, count=<spanclass="hljs-number">0</span>) <spanclass="hljs-comment"># Substitutes all occurrences with 'new'.</span>
<list> = re.findall(<regex>, text) <spanclass="hljs-comment"># Returns all occurrences as strings.</span>
<list> = re.split(<regex>, text, maxsplit=<spanclass="hljs-number">0</span>) <spanclass="hljs-comment"># Use brackets in regex to keep the matches.</span>
<list> = re.split(<regex>, text, maxsplit=<spanclass="hljs-number">0</span>) <spanclass="hljs-comment"># Use brackets in regex to include the matches.</span>
<Match> = re.search(<regex>, text) <spanclass="hljs-comment"># Searches for first occurrence of the pattern.</span>
<Match> = re.match(<regex>, text) <spanclass="hljs-comment"># Searches only at the beginning of the text.</span>
<iter> = re.finditer(<regex>, text) <spanclass="hljs-comment"># Returns all occurrences as match objects.</span>
xxxxxxxxxx