Browse Source

Regex

pull/170/head
Jure Šorn 1 year ago
parent
commit
a0cf5a6f03
2 changed files with 10 additions and 10 deletions
  1. 10
      README.md
  2. 10
      index.html

10
README.md

@ -370,7 +370,7 @@ import re
### Match Object ### Match Object
```python ```python
<str> = <Match>.group() # Returns the whole match. Also group(0). <str> = <Match>.group() # Returns the whole match. Also group(0).
<str> = <Match>.group(1) # Returns the part inside first brackets.
<str> = <Match>.group(1) # Returns part inside the first brackets.
<tuple> = <Match>.groups() # Returns all bracketed parts. <tuple> = <Match>.groups() # Returns all bracketed parts.
<int> = <Match>.start() # Returns start index of the match. <int> = <Match>.start() # Returns start index of the match.
<int> = <Match>.end() # Returns exclusive end index of the match. <int> = <Match>.end() # Returns exclusive end index of the match.
@ -378,13 +378,13 @@ import re
### Special Sequences ### Special Sequences
```python ```python
'\d' == '[0-9]' # Matches decimal characters.
'\w' == '[a-zA-Z0-9_]' # Matches alphanumerics and underscore.
'\s' == '[ \t\n\r\f\v]' # Matches whitespaces.
'\d' == '[0-9]' # Also [०-९…]. Matches a decimal character.
'\w' == '[a-zA-Z0-9_]' # Also [ª²³…]. Matches an alphanumeric or _.
'\s' == '[ \t\n\r\f\v]' # Also [\x1c-\x1f…]. Matches a whitespace.
``` ```
* **By default, decimal characters, alphanumerics and whitespaces from all alphabets are matched unless `'flags=re.ASCII'` argument is used.** * **By default, decimal characters, alphanumerics and whitespaces from all alphabets are matched unless `'flags=re.ASCII'` argument is used.**
* **As shown above, it restricts all special sequence matches to the first 128 characters and prevents `'\s'` from accepting `'[\x1c-\x1f]'` (the so-called separator characters).**
* **It restricts special sequence matches to `'[\x00-\x7f]'` (the first 128 characters) and also prevents `'\s'` from accepting `'[\x1c-\x1f]'` (the so-called separator characters).**
* **Use a capital letter for negation (all non-ASCII characters will be matched when used in combination with ASCII flag).** * **Use a capital letter for negation (all non-ASCII characters will be matched when used in combination with ASCII flag).**

10
index.html

@ -344,20 +344,20 @@ Point(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>
<li><strong><code class="python hljs"><span class="hljs-string">'re.compile(&lt;regex&gt;)'</span></code> returns a Pattern object with listed methods.</strong></li> <li><strong><code class="python hljs"><span class="hljs-string">'re.compile(&lt;regex&gt;)'</span></code> returns a Pattern object with listed methods.</strong></li>
</ul> </ul>
<div><h3 id="matchobject">Match Object</h3><pre><code class="python language-python hljs">&lt;str&gt; = &lt;Match&gt;.group() <span class="hljs-comment"># Returns the whole match. Also group(0).</span> <div><h3 id="matchobject">Match Object</h3><pre><code class="python language-python hljs">&lt;str&gt; = &lt;Match&gt;.group() <span class="hljs-comment"># Returns the whole match. Also group(0).</span>
&lt;str&gt; = &lt;Match&gt;.group(<span class="hljs-number">1</span>) <span class="hljs-comment"># Returns the part inside first brackets.</span>
&lt;str&gt; = &lt;Match&gt;.group(<span class="hljs-number">1</span>) <span class="hljs-comment"># Returns part inside the first brackets.</span>
&lt;tuple&gt; = &lt;Match&gt;.groups() <span class="hljs-comment"># Returns all bracketed parts.</span> &lt;tuple&gt; = &lt;Match&gt;.groups() <span class="hljs-comment"># Returns all bracketed parts.</span>
&lt;int&gt; = &lt;Match&gt;.start() <span class="hljs-comment"># Returns start index of the match.</span> &lt;int&gt; = &lt;Match&gt;.start() <span class="hljs-comment"># Returns start index of the match.</span>
&lt;int&gt; = &lt;Match&gt;.end() <span class="hljs-comment"># Returns exclusive end index of the match.</span> &lt;int&gt; = &lt;Match&gt;.end() <span class="hljs-comment"># Returns exclusive end index of the match.</span>
</code></pre></div> </code></pre></div>
<div><h3 id="specialsequences">Special Sequences</h3><pre><code class="python language-python hljs"><span class="hljs-string">'\d'</span> == <span class="hljs-string">'[0-9]'</span> <span class="hljs-comment"># Matches decimal characters.</span>
<span class="hljs-string">'\w'</span> == <span class="hljs-string">'[a-zA-Z0-9_]'</span> <span class="hljs-comment"># Matches alphanumerics and underscore.</span>
<span class="hljs-string">'\s'</span> == <span class="hljs-string">'[ \t\n\r\f\v]'</span> <span class="hljs-comment"># Matches whitespaces.</span>
<div><h3 id="specialsequences">Special Sequences</h3><pre><code class="python language-python hljs"><span class="hljs-string">'\d'</span> == <span class="hljs-string">'[0-9]'</span> <span class="hljs-comment"># Also [०-९…]. Matches a decimal character.</span>
<span class="hljs-string">'\w'</span> == <span class="hljs-string">'[a-zA-Z0-9_]'</span> <span class="hljs-comment"># Also [ª²³…]. Matches an alphanumeric or _.</span>
<span class="hljs-string">'\s'</span> == <span class="hljs-string">'[ \t\n\r\f\v]'</span> <span class="hljs-comment"># Also [\x1c-\x1f…]. Matches a whitespace.</span>
</code></pre></div> </code></pre></div>
<ul> <ul>
<li><strong>By default, decimal characters, alphanumerics and whitespaces from all alphabets are matched unless <code class="python hljs"><span class="hljs-string">'flags=re.ASCII'</span></code> argument is used.</strong></li> <li><strong>By default, decimal characters, alphanumerics and whitespaces from all alphabets are matched unless <code class="python hljs"><span class="hljs-string">'flags=re.ASCII'</span></code> argument is used.</strong></li>
<li><strong>As shown above, it restricts all special sequence matches to the first 128 characters and prevents <code class="python hljs"><span class="hljs-string">'\s'</span></code> from accepting <code class="python hljs"><span class="hljs-string">'[\x1c-\x1f]'</span></code> (the so-called separator characters).</strong></li>
<li><strong>It restricts special sequence matches to <code class="python hljs"><span class="hljs-string">'[\x00-\x7f]'</span></code> (the first 128 characters) and also prevents <code class="python hljs"><span class="hljs-string">'\s'</span></code> from accepting <code class="python hljs"><span class="hljs-string">'[\x1c-\x1f]'</span></code> (the so-called separator characters).</strong></li>
<li><strong>Use a capital letter for negation (all non-ASCII characters will be matched when used in combination with ASCII flag).</strong></li> <li><strong>Use a capital letter for negation (all non-ASCII characters will be matched when used in combination with ASCII flag).</strong></li>
</ul> </ul>
<div><h2 id="format"><a href="#format" name="format">#</a>Format</h2><pre><code class="python hljs">&lt;str&gt; = <span class="hljs-string">f'<span class="hljs-subst">{&lt;el_1&gt;}</span>, <span class="hljs-subst">{&lt;el_2&gt;}</span>'</span> <span class="hljs-comment"># Curly brackets can also contain expressions.</span> <div><h2 id="format"><a href="#format" name="format">#</a>Format</h2><pre><code class="python hljs">&lt;str&gt; = <span class="hljs-string">f'<span class="hljs-subst">{&lt;el_1&gt;}</span>, <span class="hljs-subst">{&lt;el_2&gt;}</span>'</span> <span class="hljs-comment"># Curly brackets can also contain expressions.</span>

Loading…
Cancel
Save