7
I’m learning Regexes by the Automate the Boring Stuff w/ Python. In one of the titles of chapter 7, the book teaches about character classes. So far quiet. I have created Character classes for vowels (re.compile(r'[aeiouAEIOU]')
), for letters and digits in ranges ((r'a-zA-Z0-9')
)... All quiet.
When I started to learn about Negative Character classes, that is, define a Character class and make it be detected, in a text, for example, strings that DO NOT have the combination of characters that I define by Character class, I started to find difficulties.
A negative class Character declares itself so: re.compile(r'[ˆaeiouAEIOU]')
, with the little hat in the front. But that’s not making Harvard negative: it’s actually detecting vowels and the little hat, if you have a little hat in your sentence.
Behold:
#Tentando (e conseguindo) detectar só VOGAIS...
>>> consonantRegex = re.compile(r'[aeiouAEIOU]')
>>> consonantRegex.findall('Robocop eats baby food. BABY FOOD')
['o', 'o', 'o', 'e', 'a', 'a', 'o', 'o', 'A', 'O', 'O']
#Tentando detectar só CONSOANTES... (Perceba o chapeuzinho)
>>> consonantRegex = re.compile(r'[ˆaeiouAEIOU]')
>>> consonantRegex.findall('Robocop eats baby food. BABY FOOD')
['o', 'o', 'o', 'e', 'a', 'a', 'o', 'o', 'A', 'O', 'O']
#Colocando um chapeuzinho na frase -> Chapeuzinho detectado
>>> consonantRegex.findall('Robocop eats baby food. ˆBABY FOOD.')
['o', 'o', 'o', 'e', 'a', 'a', 'o', 'o', 'ˆ', 'A', 'O', 'O']
Dice:
- I’m using the Interactive shell of THONNY, but I have also tested in IDLE itself, same error.
- Mac Usage. We know that Mac has that annoying Feature that gets in the way of programming: the issue of accents. When I quote, for example, he waits for a vowel to see if it can be accentuated. Like air. Then you have to quote, type a consonant, like, s, there you stay "s normal, and then delete the s to type the desired vowel previously. (If anyone knows how to turn this off, but so you can still use accents, I also appreciate A LOT).
I realized something like this when I saw the small circumflex.
– Jefferson Quesado