M
Mark Szlazak
I don't think this is "do-able" but thought I'd better check. Say I
want to replace certain names in some source code as long as they are
not properties (dot properties) of objects. I could use a regular
expression like:
rx = /(?\.)|\b)(?:name1|name2|name3)\b/g;
map = [];
map["name1"] = "a";
map["name2"] = "b";
map["name3"] = "c";
source = source.replace(rx, function ($0, $1) {return $1?
$0:map[$0]});
Dot properties like .name1 are not replaced by anything new and they
need to be "skipped" over by this regular expression but other name1
identifiers need replacement with "a".
One problem with this approach is that dot properties like .name1 are
replaced by themselves and this is just unnecessary work. Something
like a "false" return to skip replacement would be nice but the
following doesn't work.
source = source.replace(rx, function ($0, $1) {return $1?
false:map[$0]});
There are other ways to get around this by using something else
besides replace() but I wanted to see if it could be done with the
replace() method.
Is this possible?
---------------------
want to replace certain names in some source code as long as they are
not properties (dot properties) of objects. I could use a regular
expression like:
rx = /(?\.)|\b)(?:name1|name2|name3)\b/g;
map = [];
map["name1"] = "a";
map["name2"] = "b";
map["name3"] = "c";
source = source.replace(rx, function ($0, $1) {return $1?
$0:map[$0]});
Dot properties like .name1 are not replaced by anything new and they
need to be "skipped" over by this regular expression but other name1
identifiers need replacement with "a".
One problem with this approach is that dot properties like .name1 are
replaced by themselves and this is just unnecessary work. Something
like a "false" return to skip replacement would be nice but the
following doesn't work.
source = source.replace(rx, function ($0, $1) {return $1?
false:map[$0]});
There are other ways to get around this by using something else
besides replace() but I wanted to see if it could be done with the
replace() method.
Is this possible?
---------------------