Aurel
Aurel

Reputation: 631

Multiline grep regex is not working

EDIT : Solved it myself, it was a command syntax error, nothing to do with the regex.

I'm trying to match the following pattern :

(.*)
<FilesMatch "(^\.ht|~$|\.bak$|\.BAK$|\.old$)">
(.*)
Order Allow,Deny Deny from all
(.*)
</FilesMatch>
(.*)
<DirectoryMatch "(/CVS/|.svn)">
(.*)
Order Allow,Deny Deny from all
(.*)
</DirectoryMatch>
(.*)
(.*) meaning anything

Using grep -P "regex" and this regex :

<FilesMatch \"\(\^\\\.ht\|~\$\|\\\.bak\$\|\\\.BAK\$\|\\\.old\$\)\">(.*\n){1,}Order Allow,Deny Deny from all(.*\n){1,}<\/FilesMatch>(.*\n){1,}<DirectoryMatch \"\(\/CVS\/\|\.svn\)\">(.*\n){1,}Order Allow,Deny Deny from all(.*\n){1,}<\/DirectoryMatch>

Over the following example file :

<FilesMatch "(^\.ht|~$|\.bak$|\.BAK$|\.old$)">
Order Allow,Deny Deny from all
</FilesMatch>
<DirectoryMatch "(/CVS/|.svn)">
Order Allow,Deny Deny from all
</DirectoryMatch>

According to regex101, it is supposed to work but it doesn't, do you have any idea about what's wrong ?

Thanks for your help.

Upvotes: 1

Views: 163

Answers (1)

Aurel
Aurel

Reputation: 631

Okey it's my own fault, I used grep -P "regex" instead of grep -P 'regex'...

It also works with pcregrep -M 'regex'.

Thanks anyway !

Upvotes: 2

Related Questions