I'm looking for a regex pattern that will find quoted strings
(double quotes) but skip (double-)quoted strings containing any of
the following characters: $'"\ (dollar sign, single quote, double
quote, backslash)
At first I tried "[^\$'"\\]+?" but it was matching the end of one
quoted string and the beginning of the next...
(?<!\\)"[^\$'"\\\r\n]*(?<!\\)"
First off, (?<!\\) is a negative lookbehind assertion that the
character before the " is not a backslash.
I've added \r and \n into the exclusion, which should stop any cases
crossing line endings.
And * means zero or more, which is equivalent to +? which means
optionally 1 or more.
It works in your test case, finding only the last two strings. It is
unlikely to work perfectly it every possible case, but if you find a
case that fails, perhaps it can also be handled.
Enjoy,
Peter.
PS: Top posting is good for cases like this.
Here are some strings that should fail to match:
// contains escaped quotes and single quotes, the tricky part is the
last quoted string, which should fail...
$str = "`zcol ACOL` NUMBER(32,2) DEFAULT 'The \"cow\" (and Jim''s
dog) jumps over the moon' PRIMARY, INTI INT AUTO DEFAULT 0,
zcol2\"afs ds";
// contains dollar signs, backslashes and single quotes
ADOConnection::outp( "
-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>",false);
// contain single quotes
if (strncmp($val,"'",1) != 0 && substr($val,strlen($val)-1,1) != "'") {
// strings that should match
$myvar = "this is my quoeted ".$and_another_var." and another string";
Also, quoted strings should not be preceded with a backslash.
I've read and reread the BBEdit docs (which are great) but I've been
unable to come up with a method that passes all of these tests.
I never had any idea this could be such a complicated problem. Does
anyone see what I'm missing?
PS: I've got a new version of the PHP clipping set ready for
release, but need to finish building the new server first...
Ted Stresen-Reuter
http://clevernet.biz
http://www.tecnotertulia.com
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>
--
"You're a genius" says Rich Siegel. Who am I to argue?
<http://www.stairways.com/> <http://download.stairways.com/>
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>