在结束之后找到额外的空格/新行?> (php标签) [英] Find extra space / new line after a closing ?> (php tag)

查看:129
本文介绍了在结束之后找到额外的空格/新行?> (php标签)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我怎样才能轻松找到它?我有1000个(PHP标签)在这个应用程序中的文件和100000行代码。

理想情况下,在一些正则表达式结合使用find grep在unix盒子上运行。

解决方案

这里的问题是普通的grep不匹配多行。所以,我会安装 pcregrep 并尝试下面的命令:

  pcregrep -rMl'\?> [\s\\\
] + \ z'*

这将使用PCRE多行匹配( -M -r 部分)中的所有文件>部分),并且只列出它们的文件名( -l <​​/ code>部分)。



至于模式,匹配?>> ,后跟1个或多个空格或换行符,接着是文件的结尾 \ z 。我发现,当我在我的文件夹上运行这个文件时,许多PHP文件实际上只有一个换行符。所以你可以把这个正则表达式更新为'\?> [\\\\\\\\\\\\\\\\\\\\\\\]在单个 \\\
字符结束符之上。

最后,您可以使用 od -c filename 打印文件的明确表示,如果您需要检查其确切的字符序列结尾。


So I have a space/new line after a closing ?> (php tag) that is breaking my application.

How can I find it easily I have 1000 of files and 100000 lines of code in this app.

Ideally im after some regex combined with find grep to run on a unix box.

解决方案

The problem here is normal grep doesn't match multiple lines. So, I would install pcregrep and try the following command:

pcregrep -rMl '\?>[\s\n]+\z' *

This will match all files in the folder and subfolders (the -r part) using PCRE multiline match (the -M part), and only list their filenames (the -l part).

As for the pattern, well that matches ?> followed by 1 or more whitespace or newline characters, followed by the end of the file \z. I found though, when I ran this on my folder, many of the PHP files do in fact end with a single newline. So you can update that regex to be '\?>[\s\n]+\n\z' to match files with whitespace over and above the single \n character terminator.

Lastly, you can always use od -c filename to print unambiguous representation of the file if you need to check its exact character sequence ending.

这篇关于在结束之后找到额外的空格/新行?&gt; (php标签)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆