Search code examples
regexlinuxunixgrepbbedit

Use Grep to find blocks of text between two phrases (including the phrases)


Is it possible to use grep to high lite all of the text starting with:

mutablePath = CGPathCreateMutable();

and ending with:

CGPathAddPath(skinMutablePath, NULL, mutablePath);

Where there is an arbitary amount of text in between those two phrases?

NOTE: I have to use grep because I'm using BBEdit.


Solution

  • You will need to use GNU grep:

    grep -oPz 'mutablePath = CGPathCreateMutable\(\);.*?(\n.*?)*.*?CGPathAddPath\(skinMutablePath, NULL, mutablePath\);' file
    

    If you don't have GNU grep, you could use pcregrep to achieve the same thing:

    pcregrep -M 'mutablePath = CGPathCreateMutable\(\);.*(\n|.)*CGPathAddPath\(skinMutablePath, NULL, mutablePath\);' file