hallo again BSF,
Allerdings habe ich in meinem String ausschließlich einzelne Hochkommata,
wenn ich also das hier --> str = "select xyz from table1 where col1 like "c%" and col2 like 'd%'";
in das hier --> str = "select xyz from table1 where col1 like 'c%' and col2 like 'd%'"; ändere, bekomme ich das -->
select xyz from table1 where col1 like LOWER('c%' and col2 like 'd%')
ups ... warum? ... das darf eigentlich ueberhaupt nicht sein. aber ein test
legt tatsaechlich nahe, dass die RegExp-engine dort wirklich »gierig« suchend
zu werke geht, alles zwischen dem ersten und dem letzten vorkommen des zuerst
*gematchten* zeichens mitnimmt, und dabei das ausdruecklich nicht gierig
formulierte muster einfach ignoriert (C&P >> jconsole.com):
var str, regX = (/(['"])([^\\1]*)\1/g);
str = "select xyz from table1 where col1 like 'a%' and col2 like 'b%' and col3 like \"xy%\" and col4 like 'ik%'";
print(regX.test(str));
print(str.replace(regX, (function () {
alert("arguments[0] : " + arguments[0] + "\narguments[1] : " + arguments[1] + "\narguments[2] : " + arguments[2]);
return ("LOWER(" + arguments[1] + arguments[2] + arguments[1] + ")");
})));
str = "select xyz from table1 where col1 like \"c%\" and col2 like \"d%\" and col3 like 'ab%' and col4 like \"cd%\"";
print(regX.test(str));
print(str.replace(regX, (function () {
alert("arguments[0] : " + arguments[0] + "\narguments[1] : " + arguments[1] + "\narguments[2] : " + arguments[2]);
return ("LOWER(" + arguments[1] + arguments[2] + arguments[1] + ")");
})));
Hast Du da noch einmal einen Tip?
fuehrt man das muster aber mal auf jeweils ein bestimmtes hochkomma zurueck,
und ist damit nicht mehr auf die »backreference« angewiesen, laufen die jeweils
zugeordneten testcases anstandlos durch (C&P >> jconsole.com):
var str, regX;
str = "select xyz from table1 where col1 like 'a%' and col2 like 'b%' and col3 like \"xy%\" and col4 like 'ik%'";/*
regX = (/(['"])([^\\1]*)\1/g);*/
regX = (/(')([^']*)'/g);
print(regX.test(str));
print(str.replace(regX, "LOWER($1$2$1)"));
str = "select xyz from table1 where col1 like \"c%\" and col2 like \"d%\" and col3 like 'ab%' and col4 like \"cd%\"";/*
regX = (/(['"])([^\\1]*)\1/g);*/
regX = (/(")([^"]*)"/g);
print(regX.test(str));
print(str.replace(regX, (function () {
alert("arguments[0] : " + arguments[0] + "\narguments[1] : " + arguments[1] + "\narguments[2] : " + arguments[2]);
return ("LOWER(" + arguments[1] + arguments[2] + arguments[1] + ")");
})));
schoen - damit waere Dein problem geloest. die generische loesung, die das
gemischt auftretende vorkommen beide arten hochkommata unterstuetzt, bliebe
aber weiter fehlerhaft ...
(test, test ,test ...) ...
...
ich weiss zwar immer noch nicht, warum die RegExp-implementationen aller
getesteten browser so einig in der gierigen interpretation des mit der
»backreference« arbeitenden ausdrucks waren - zumindest sind sie sich auch
bei folgendem test einig, der das problem zwar loest, indem das muster
nocheinmal ausdruecklich als *nicht gierig* gekennzeichnet wird, mich aber
trotzdem noch fragend zuruecklaesst (C&P >> jconsole.com):
var str;/*
var regX = (/(['"])([^\\1]*)\1/g);*/
var regX = (/(['"])([^\\1]*?)\1/g);
str = "select xyz from table1 where col1 like 'a%' and col2 like 'b%' and col3 like \"xy%\" and col4 like 'ik%'";
print(regX.test(str));
print(str.replace(regX, "LOWER($1$2$1)"));
str = "select xyz from table1 where col1 like \"c%\" and col2 like \"d%\" and col3 like 'ab%' and col4 like \"cd%\"";
print(regX.test(str));
print(str.replace(regX, (function () {
alert("arguments[0] : " + arguments[0] + "\narguments[1] : " + arguments[1] + "\narguments[2] : " + arguments[2]);
return ("LOWER(" + arguments[1] + arguments[2] + arguments[1] + ")");
})));
so long - peterS. - pseliger@gmx.net
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:) n3;} n4:} ss:} de:µ js:} mo:? zu:]