mirror of
https://github.com/satwikkansal/wtfpython
synced 2024-09-22 15:41:43 +02:00
Merge c3a7526096
into b89710a415
This commit is contained in:
commit
bb4d50e8df
2
CONTRIBUTORS.md
vendored
2
CONTRIBUTORS.md
vendored
@ -24,7 +24,7 @@ Following are the wonderful people (in no specific order) who have contributed t
|
|||||||
| Jongy | [Jongy](https://github.com/Jongy) | [#208](https://github.com/satwikkansal/wtfpython/issues/208), [#210](https://github.com/satwikkansal/wtfpython/issues/210), [#233](https://github.com/satwikkansal/wtfpython/issues/233) |
|
| Jongy | [Jongy](https://github.com/Jongy) | [#208](https://github.com/satwikkansal/wtfpython/issues/208), [#210](https://github.com/satwikkansal/wtfpython/issues/210), [#233](https://github.com/satwikkansal/wtfpython/issues/233) |
|
||||||
| Diptangsu Goswami | [diptangsu](https://github.com/diptangsu) | [#193](https://github.com/satwikkansal/wtfpython/issues/193) |
|
| Diptangsu Goswami | [diptangsu](https://github.com/diptangsu) | [#193](https://github.com/satwikkansal/wtfpython/issues/193) |
|
||||||
| Charles | [charles-l](https://github.com/charles-l) | [#245](https://github.com/satwikkansal/wtfpython/issues/245)
|
| Charles | [charles-l](https://github.com/charles-l) | [#245](https://github.com/satwikkansal/wtfpython/issues/245)
|
||||||
|
| Nuno André | [nuno-andre](https://github.com/nuno-andre) | [#247](https://github.com/satwikkansal/wtfpython/issues/245)
|
||||||
---
|
---
|
||||||
|
|
||||||
**Translations**
|
**Translations**
|
||||||
|
37
README.md
vendored
37
README.md
vendored
@ -48,6 +48,7 @@ So, here we go...
|
|||||||
+ [▶ All-true-ation *](#-all-true-ation-)
|
+ [▶ All-true-ation *](#-all-true-ation-)
|
||||||
+ [▶ The surprising comma](#-the-surprising-comma)
|
+ [▶ The surprising comma](#-the-surprising-comma)
|
||||||
+ [▶ Strings and the backslashes](#-strings-and-the-backslashes)
|
+ [▶ Strings and the backslashes](#-strings-and-the-backslashes)
|
||||||
|
+ [▶ Blurred boundaries](#-blurred-boundaries)
|
||||||
+ [▶ not knot!](#-not-knot)
|
+ [▶ not knot!](#-not-knot)
|
||||||
+ [▶ Half triple-quoted strings](#-half-triple-quoted-strings)
|
+ [▶ Half triple-quoted strings](#-half-triple-quoted-strings)
|
||||||
+ [▶ What's wrong with booleans?](#-whats-wrong-with-booleans)
|
+ [▶ What's wrong with booleans?](#-whats-wrong-with-booleans)
|
||||||
@ -1351,6 +1352,42 @@ True
|
|||||||
```
|
```
|
||||||
- This means when a parser encounters a backslash in a raw string, it expects another character following it. And in our case (`print(r"\")`), the backslash escaped the trailing quote, leaving the parser without a terminating quote (hence the `SyntaxError`). That's why backslashes don't work at the end of a raw string.
|
- This means when a parser encounters a backslash in a raw string, it expects another character following it. And in our case (`print(r"\")`), the backslash escaped the trailing quote, leaving the parser without a terminating quote (hence the `SyntaxError`). That's why backslashes don't work at the end of a raw string.
|
||||||
|
|
||||||
|
---
|
||||||
|
### ▶ Blurred boundaries
|
||||||
|
```py
|
||||||
|
>>> re.match('wtf', 'wtfwtf')
|
||||||
|
<re.Match object; span=(0, 3), match='wtf'>
|
||||||
|
>>> re.match('wtf', 'wtf')
|
||||||
|
<re.Match object; span=(0, 3), match='wtf'>
|
||||||
|
```
|
||||||
|
|
||||||
|
- `\B` matches the empty string, but only when it **_is not_** at the beginning or end of a word.
|
||||||
|
```py
|
||||||
|
>>> re.match('wtf\B', 'wtfwtf')
|
||||||
|
<re.Match object; span=(0, 3), match='wtf'>
|
||||||
|
>>> re.match('wtf\B', 'wtf')
|
||||||
|
None
|
||||||
|
```
|
||||||
|
|
||||||
|
- `\b` matches the empty string, but only when it **_is_** at the beginning or end of a word.
|
||||||
|
|
||||||
|
```py
|
||||||
|
>>> re.match('wtf\b', 'wtfwtf')
|
||||||
|
None
|
||||||
|
>>> re.match('wtf\b', 'wtf')
|
||||||
|
None
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 💡 Explanation
|
||||||
|
- `\b` and `\B` are anchor symbols of the regular expression syntax. But, unlike `\B`, `\b` is also a valid escape as a string literal (the backspace character). Thus in order for the `re` lexer to interpret the word boundary, it has to be escaped when is not used within raw literals.
|
||||||
|
```py
|
||||||
|
>>> re.match('wtf\\b', 'wtf')
|
||||||
|
<re.Match object; span=(0, 3), match='wtf'>
|
||||||
|
>>> re.match(r'wtf\b', 'wtf')
|
||||||
|
<re.Match object; span=(0, 3), match='wtf'>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### ▶ not knot!
|
### ▶ not knot!
|
||||||
|
Loading…
Reference in New Issue
Block a user