【问题标题】:Multiline grep regex is not working多行 grep 正则表达式不起作用
【发布时间】:2016-08-16 05:52:16
【问题描述】:

编辑: Solved it我自己,这是一个命令语法错误,与正则表达式无关。

我正在尝试匹配以下模式:

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

使用grep -P "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>

通过以下示例文件:

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

根据regex101,它应该可以工作,但它没有,你知道出了什么问题吗?

感谢您的帮助。

【问题讨论】:

    标签: regex linux apache grep


    【解决方案1】:

    好吧,这是我自己的错,我用grep -P "regex"而不是grep -P 'regex'...

    它也适用于pcregrep -M 'regex'

    还是谢谢!

    【讨论】:

    • 下一次,显示不起作用的确切咒语。
    猜你喜欢
    • 1970-01-01
    • 2012-10-26
    • 2015-06-19
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多