Reading text between two lines

Hi all

I want to check if certain text is between two lines, e.g. - If “Receipt” is between “Photo of iPad” and “Test”

LineNames

Any help would be greatly appreciated

Thanks :slight_smile:

1 Like

Try this

strText = strText .Replace(Environment.NewLine,string.Empty)

bool Contains = Regex.Match(strText,“(?<=Photo of iPad)(.*?)(?=Test)”).Value.Contains(“Receipt”)

1 Like

Hi @vvaidya

Apologies for being a bit slow but I couldn’t work out if you meant do a match or an If (the condition throw me, and I didn’t think it would fit in an Assign) but neither work:

If error

Where am I going wrong?

Thanks!

1 Like

You don’t need matches in this case, just if condition. In your if condition remove quotes and you should be good.

If (Regex.Match(strQuote,“(?<=Photo of iPad)(.*?)(?=Test)”).Value.Contains(“Receipt”))

Thanks,
Vinay

1 Like

Hi Vinay

That makes more sense, thanks.

Now I’m getting this error:

Saying that Regex is not declared. Is there something else I need to do for this?

Thanks!

1 Like

Hey @Short

You have to import “System.Text.RegularExpression” namespace in your project then you will be able to use Regex.

or can use as well like System.Text.RegularExpression.Regex but better to use import namespace approach.

Regards…!!
AKsh

2 Likes

Amazing, thank you!