1
I have the following situation:
text_1 = O cachorro correu com o gato
text_2 = O carro passou e o cachorro foi atrás
text_3 = Sempre que chego em casa meu cachorro pula em mim
text_4 = Ele foi correndo atrás do sonho
text_5 = O cachorro latiu para o carteiro
text_6 = Quando seu dono ordenou, corra cachorro
I want to take groups with "cachorro, pul\w+, corre\w+ e foi"
, but in all groups the word dog is present.
I tried to:
re.search((?:\s(cachorro|corre\w+|foi|pul\w+)){2,},text_n)
What gives match on:
text_1 = cachorro correu
text_2 = cachorro foi
text_3 = cachorro pula
text_4 = foi correndo
text_5 = None
text_6 = corra cachorro
My problem is with the match text_4, that result does not suit me.
What I want is to know if there is a way to match in groups using Regular Expressions where a certain word in the case dog, appear at least once.
Other variations of the word correr
and pular
may occur together with dog.
Obg to all.
You are a little confused about what your real need is. Regular expression should return any occurrence of
cachorro
followed by another word or just occurrences withcorre
,foi
andpul*
? For in the text you say one thing and in the code you seem to do another.– Woss
The example is just an illustration, I want to pick up groups, no matter the order, where the word dog is present. I’ve tried
re.search('(?:cachorro|(?:\s(corre\w+|foi|pul\w+)){2})', text)
what would match {Ocachorro foi pular
a cerca} and tb would be useful to me, but I would pick up yet another text {Hefoi correndo
behind the dream} and would not serve me.– Mueladavc
But this did not answer my question: should one search ONLY for the verbs run, go and jump or may there be the occurrence of others that were not listed? For example, "The dog barked at the postman" should be a result?
– Woss
Sorry, I tried to edit and the time passed, but yes, groups with the words
cachorro, pul\w+, corre\w+, foi
no matter the order or quantity, but in which the word dog is present.– Mueladavc