<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Re on Cheat Sheet</title><link>/tags/re/</link><description>Recent content in Re on Cheat Sheet</description><generator>Hugo</generator><language>en</language><lastBuildDate>Tue, 16 Jun 2026 00:00:00 +0000</lastBuildDate><atom:link href="/tags/re/index.xml" rel="self" type="application/rss+xml"/><item><title>re</title><link>/programming/python/re/</link><pubDate>Tue, 16 Jun 2026 00:00:00 +0000</pubDate><guid>/programming/python/re/</guid><description>&lt;h1 id="re"&gt;&lt;code&gt;re&lt;/code&gt;&lt;a class="anchor" href="#re"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Python&amp;rsquo;s built-in module for regular expressions.&lt;/p&gt;
&lt;h2 id="basic-functions"&gt;Basic Functions&lt;a class="anchor" href="#basic-functions"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;re.compile(pattern: str, flags: int = 0) -&amp;gt; re.Pattern&lt;/code&gt;: Compiles a regex string into a reusable &lt;code&gt;re.Pattern&lt;/code&gt; object.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;re.search(pattern: str, string: str, flags: int = 0) -&amp;gt; re.Match | None&lt;/code&gt;: Scans through &lt;code&gt;string&lt;/code&gt; for the first location where &lt;code&gt;pattern&lt;/code&gt; matches.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;re.match(pattern: str, string: str, flags: int = 0) -&amp;gt; re.Match | None&lt;/code&gt;: Checks for a match only at the beginning of &lt;code&gt;string&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;re.fullmatch(pattern: str, string: str, flags: int = 0) -&amp;gt; re.Match | None&lt;/code&gt;: Checks whether the entire &lt;code&gt;string&lt;/code&gt; matches &lt;code&gt;pattern&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;re.finditer(pattern: str, string: str, flags: int = 0) -&amp;gt; Iterator[re.Match]&lt;/code&gt;: Returns an iterator yielding &lt;code&gt;re.Match&lt;/code&gt; objects over all non-overlapping matches.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;re.findall(pattern: str, string: str, flags: int = 0) -&amp;gt; list[str] | list[tuple[str, ...]]&lt;/code&gt;: Returns all non-overlapping matches as a list of strings (0 or 1 capturing group) or tuples (multiple capturing groups).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;re.sub(pattern: str, repl: str | Callable[[re.Match], str], string: str, count: int = 0, flags: int = 0) -&amp;gt; str&lt;/code&gt;: Replaces matches with &lt;code&gt;repl&lt;/code&gt; and returns the new string.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;re.split(pattern: str, string: str, maxsplit: int = 0, flags: int = 0) -&amp;gt; list[str]&lt;/code&gt;: Splits &lt;code&gt;string&lt;/code&gt; by occurrences of &lt;code&gt;pattern&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="flags"&gt;Flags&lt;a class="anchor" href="#flags"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Passed via the &lt;code&gt;flags&lt;/code&gt; parameter in module-level functions and &lt;code&gt;re.compile()&lt;/code&gt;. Combine multiple flags with the bitwise OR operator &lt;code&gt;|&lt;/code&gt;.&lt;/p&gt;</description></item></channel></rss>