preg match all - How do I define the starting line for preg_match in PHP? -


im using preg_match find word in text file. however, want define starting line preg_match starts search. how can make preg_match ignore first 5 lines? additionally, have code automatically delete preg_matched word file, im not sure "start keyword" work here.

heres code im using.

$contents = file_get_contents($file); $pattern = preg_quote($searchfor, '/'); $pattern = "/\b$pattern\b/m"; if(preg_match_all($pattern, $contents, $matches)) 

thank in advance.

prefixing pattern with

^((.*)\n){5}\k 

should discard first 5 rows of search please see demo below

https://regex101.com/r/wfqazl/2

your code this

$contents = file_get_contents($file); $pattern = preg_quote($searchfor, '/'); $pattern = "/^((.*)\n){5}\k\b$pattern\b/m"; if(preg_match_all($pattern, $contents, $matches)) 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -