This commit is contained in:
Nuno André 2021-04-28 07:47:13 -05:00 committed by GitHub
commit bb4d50e8df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

2
CONTRIBUTORS.md vendored
View File

@ -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) |
| 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)
| Nuno André | [nuno-andre](https://github.com/nuno-andre) | [#247](https://github.com/satwikkansal/wtfpython/issues/245)
---
**Translations**

37
README.md vendored
View File

@ -48,6 +48,7 @@ So, here we go...
+ [ All-true-ation *](#-all-true-ation-)
+ [ The surprising comma](#-the-surprising-comma)
+ [ Strings and the backslashes](#-strings-and-the-backslashes)
+ [ Blurred boundaries](#-blurred-boundaries)
+ [ not knot!](#-not-knot)
+ [ Half triple-quoted strings](#-half-triple-quoted-strings)
+ [ 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.
---
### ▶ 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!