REGEX issue, selecting an sql query with multiple new lines -
i trying select every query select in start , limit in end, example:
$selquery = "select disticnt c.firstname,c.lastname,c.id clientid,qc.category_name,qr.cid,qr.catid,qr.rhid cms_question_report qr, cms_clients c,cms_questioncategory qc ,cms_reporthistory rh c.id=qr.cid , qr.rhid=rh.id , qr.catid='".$objarray['catid']."' , qr.catid=qc.id , c.id in($selclids) limit $page_no,$this->limit";
and not select other query doesn't contain limit. regex thought work this:
select .*\n* limit
where i'm stating has start "select" other characters , ends limit, issue don't know how handle \n*, have multiple unknown number of new lines , in each line there unknown characters, i'm assuming should go \n*.\n.* , on, there way can select character including new line.
i have tried using solution: regex match character including new lines , adjusted regex to:
select /s* limit
but didn't work well.
also tried:
select (.|\n)* limit
but didn't work.
as @commusoft commented sql queries have structure cannot correctly recognized using regular expressions.
but if want find in source code strings containing queries beginning select , having word limit , allowing eols between quotation marks, use this:
\"select([^"]|\n|\"[^";]*\")*limit([^"]|\n|\"[^";]*\")*\";
demo here
this regex match string delimited double quotes words select , limit, , allowing in between 0 or more
- characters not double quotes
\n
- a pair of double quotes character in between
;
this may need, depends on code looks like. example if build query catenating variables won't work.
note depending on operating system end of line mark can \r\n or \r.