Exercício de RegEx #0: Existencialismo
Escreva três expressões regulares: uma chamada "nothing" que corresponda apenas a uma string vazia, uma chamada "anything" que corresponda a qualquer string, vazia ou não, e uma chamada "something" que corresponda somente a strings não vazias.
Exemplo
txt1 = ""
txt2 = "This is not an empty string."
nothing = "yourregularexpressionhere"
anything = "yourregularexpressionhere"
something = "yourregularexpressionhere"
bool(re.match(nothing, txt1)) ➞ True
bool(re.match(nothing, txt2)) ➞ False
re.findall(nothing, txt1) ➞ [""]
re.findall(nothing, txt2) ➞ []
bool(re.match(anything, txt1)) ➞ True
bool(re.match(anything, txt2)) ➞ True
re.findall(anything, txt1) ➞ [""]
re.findall(anything, txt2) ➞ ["This is not an empty string."]
bool(re.match(something, txt1)) ➞ False
bool(re.match(something, txt2)) ➞ True
re.findall(something, txt1) ➞ []
re.findall(something, txt2) ➞ ["This is not an empty string."]Observações
- Você não precisa escrever uma função, apenas o padrão.
- Não remova
import redo código. - Encontre mais informações sobre RegEx em Recursos.
- Você pode encontrar todos os desafios desta série na minha coleção RegEx básico.