'Regex multiline matching

I was wondering if it's possible to make a regular expression to find all of the text that is in between the following two strings:

mutablePath = CGPathCreateMutable();
...
CGPathAddPath(skinMutablePath, NULL, mutablePath);

Basically, the first and last lines will always be the same, and there will be a whole bunch of random stuff in between. I'm using the find feature in xCode and would like to count the number of lines that appear between all instances of the first and last line from above.

Is this even possible?



Solution 1:[1]

Xcode does not support multi-line regex matching. You'll have to search for your first and last line and count the lines in between by yourself.

Solution 2:[2]

Looks like you can use the DOTALL modifier,

I was able to find a block of code like yours with this regex:

(?s)mutablePath = CGPathCreateMutable\(\);.+CGPathAddPath\(skinMutablePath, NULL, mutablePath\);

More info in the ICU regex documentation here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 D_4_ni
Solution 2 danwood