Select everything after a word and stop at a specific word (take all if not there)

Hi, I would like to select everything between the word “start” and “end”.
Like this in Regex: (?<=start)(?s)(.*)(?=end)

Problem:
If the word “end” is not there it should still select everything after start.

1 Like

I tried, but no luck.
As an alternative, you can have two regex expression based on end is there in the string or not.

If string.Contains("end")
    (?<=start)(?s)(.*)(?=end)
else
    (?<=start)(?s)(.*)
End If
2 Likes

@Jizh

Can you try the below pattern. Same logic as Karthik suggested

((?<=start)(?s)(.*)(?=end))|((?<=start)(?s)(.*))

2 Likes

This works for both single line and multi line

((?<=start)(?s)(.?(?=end)|.))

1 Like

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