Find PHP files with nested spaces

Spaces in PHP files are sometimes problematic, so I'm trying to find files that meet common problem criteria. I try to find all recursive files that have one or both of these conditions:

1) Does not start with the character < or # .

and / or

2) Does not end with the > character, unless it ends in tight binding, followed by any number of newline lines.

I think the first condition would be the following: $[^<#]

I think the second condition would be the following: [ [^>^] | [}\n*^]] [ [^>^] | [}\n*^]]

However, note that in my naive regular expressions $ and ^ , the beginning and end of the file are represented, not any line in the file. And even with those, considering that they were correct, how would I combine them? Like this?

 [$[^<#]] | [[ [^>^] | [}\n*^]]] 

Then, putting them in grep:

 grep -r [$[^<#]] | [[ [^>^] | [}\n*^]]] * 

Obviously this does not work (tm). Can someone teach me how to fix errors? Thanks.

This is a good file:

 <?php ?> 

Like this:

 <?php function someFunc(){ } ‏ 

And this is also good:

 #!/usr/bin/php -q <?php ?> 

The leading HTML is excellent:

 <html> <?php echo '</html>'; ?> 

HTML trailing is good too:

 <?php echo '<html>'; ?> </html> 

This is bad (leading new line):

 ‏ <?php ?> 

This is also bad (leading space):

 ‏ <?php ?> 

This is also bad (the end line of a new line):

 <?php ?> ‏ 
+7
source share
1 answer

Expression expressions very quickly, I think, do what you want. This is pretty late, and for some reason I am on stackoverflow. Despite this, I hope that I have received your request.

Try this regular expression /\A(?:\s+.*>|[^<#].*>\s*|<.*>\s+)\Z/s . Clarification here: http://regex101.com/r/cT7eY5

I hope this help. If I misunderstood you, clarify and I will try to customize the expression.

+2
source

All Articles