Multiline search pattern with RegEx

I’ve been a big fan of RegEx since I first started using it, but I’ve run into a snag. I’ve never had to search for a multiline section of text before, and I can’t seem to get it to work.

Here’s what I’m trying to search for. Some of the individual lines are not unique in this document, but together in this order they are unique, so that’s how I want to search for it.

item: Custom Script Item
Filename=Remove MSI.wse
Variable Name1=TEST
Variable Value1=Insert GUID Here
end

I’ve tried using Xojo’s line continuation, but that did work. Here’s what I tried.

rg6.SearchPattern = "\bitem: Custom Script Item "_
+ "Filename=Remove MSI.wse "_
+ "Variable Name1=TEST "_
+ "Variable Value1=Insert GUID Here "_
+ "end\b"

Any suggestions would be most appreciated!

Check out the regex options dotMatchAll and TreatTargetAsOneLIne. See https://documentation.xojo.com/api/text/regular_expressions/regex.htmlOptions

Unfortunately, there are no examples with those options, and it doesn’t tell me if I should be using the XOJO line break with them or not.

^item: Custom Script Item\RFilename=Remove MSI\.wse\RVariable Name1=TEST\RVariable Value1=Insert GUID Here\Rend$

\R will match any line ending.

1 Like
rg6.SearchPattern = "\bitem: Custom Script Item\RFilename=Remove MSI.wse\RVariable Name1=TEST\RVariable Value1=Insert GUID Here\Rend$\b"

This didn’t work. Did I structure it corectly?

I got it! There was two spaces at the start of three of those lines…I had to add them in.

Thanks Kem!!

1 Like