Regex for finding Word and getting text

Hello,

Im looking for a way to copy a specific part out of a mail body. The part always begins and ends with the same word but the content is different. E.g.:

Input>>
Hello Mr. X,
Im doing well.
StartWord: this is the sentence i would like to receive.
Maybe there are some more lines

Best regards,

Output>>
string = “this is the sentence i would like to receive. Maybe there are some more lines”

Could somebody help me to receive the text in a string between “StartWord” and “Best regards”?

Best regards

HI @Pathler

You can try this expression
(?s)(?<=StartWord:\s)(.*?)(?=\nBest\sregards)

Regards
Sudharsan

@Pathler
have a look here:
grafik

the . will exclude the \n linebreak. That’s why we used the \s\S pattern in an ungreedy manner
grafik

1 Like

thanks, that helped quit well!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.