Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expressions in PHP

Status
Not open for further replies.

jpadie

Technical User
Nov 24, 2003
10,094
FR
I'm having some trouble constructing a pattern that works adequately with php's preg_* functions. when I try various patterns in external agents it seems to work fine. very bizarre.

I am writing a partial sql parsing engine for a project to port wordpress to PDO abstraction layer compatibility and one of the things I need to achieve is to remove all quoted parameters.

the problem I'm running into is with escaped content. take for example this clause

Code:
Update table set field1 = "somevalue", field2  = 'John\'s toy', field3 = "<img href=\"image.php\">"

I'm looking for an array of extracts which should have

Code:
[0] => somevalue
[1] => John\'s toy
[2] => <img href=\"image.php\">

the pattern that i have working in reggy (Mac OSX regular expressions GUI) is
Code:
[^\\]('|")(.*?)[^\\]\1
I'd expect this to look like so in php
Code:
$pattern = '/[^\\\\](\'|")(.*?)[^\\\\]\\1/imx';

but this produces rubbish results.

is the php PCRE implementation bust or am I just in a head spin (in which case an alternative solution would be much appreciated)? I'm quite prepared to believe that i've just got my head on backwards - i've had to design far too many regular expressions for this project and my brain is a-burnin...

thanks
Justin


 
please disregard. the issue was related to the escaping of a serialised object that i was trying to parse.

the pattern works ok although does not deliver what I need, but that, perhaps, is the subject of a different post!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top