robinson has asked for the wisdom of the Perl Monks concerning the following question:
Hello:
For a long time I was using grep with the option "-P" to turn on Perl pattern matching to detect if a file contained a given text. The pattern could be very simple or very complicated so I needed regular expressions.
Then I ran into some trouble where grep would complain that "PCRE's backtracking limit is exceeded". I could never find a working solution so I decided that instead of using grep to emulate Perl, I could just use a Perl one-liner and cut the middle man.
Now I'm running into some problems with Perl because for some reason it is refusing to match some files even thought everything seems correct and if I take the same expression and use it with 'grep -P', it has no trouble finding the match.
Here is a portion of my Perl one-liner (on linux). If there was a match, it would exit with code 0 (trying to emulate grep's behavior)
Here is a partial content of the file "filename.txt":perl -ne "/(?s)<\?php.+?[\\$]{1}/ and exit 0; exit 1" filename.txt ; e +cho $?
Here is the same partial content in hex (because there are some not visible chars there):<?php $t60="
For the life of me I can not find a way to make Perl to match that. If I use the same expression with Grep, it has no problem matching it:0000000 3c 3f 70 68 70 20 20 0d 0a 24 74 36 30 3d 22 0a 0000020
grep -Pzo "(?s)<\?php.+?[\\$]{1}([0-9a-zA-Z]+)=['\"]+" filename.txt
What am I missing? I would really appreciate your help as every Regex program and editor and debugger says the regex is correct and like I said, grep has no problem at all matching it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unable to match newline
by Corion (Patriarch) on Nov 17, 2015 at 19:14 UTC | |
by robinson (Novice) on Nov 17, 2015 at 20:09 UTC | |
by Preceptor (Deacon) on Nov 20, 2015 at 16:04 UTC | |
|
Re: Unable to match newline
by linuxer (Curate) on Nov 17, 2015 at 19:42 UTC | |
by robinson (Novice) on Nov 17, 2015 at 19:57 UTC | |
by linuxer (Curate) on Nov 17, 2015 at 20:10 UTC | |
by robinson (Novice) on Nov 17, 2015 at 20:37 UTC |