I am new to regex and could use some help. Each block is separated by two new line characters \n\n
. I need to get the amount of dogs but only if that block contains a medium sized dog
I have the string
"4211 dogs ate 2 pounds
chris (large)
3454 dogs ate 8 pounds
john (medium)
alex (small)
4211 dogs ate 2 pounds
morgan (small)
"
//regex \d+(?=\sdogs\sate\s\d+\spounds[\s\S]*(?!\n\n)\(medium\))
using this regex:
\d+(?=\sdogs\sate\s\d+\spounds[\s\S]*(?!\n\n)\(medium\))
almost works. But the problem with it is that when it finds the pattern \n\n
it doesn't stop until it finds the last occurrence of \n\n
. I need it to stop when it finds the first occurrence of \n\n
not the last, in order to prevent it from finding patterns in other blocks.