Link to home
Start Free TrialLog in
Avatar of SweatCoder
SweatCoderFlag for United States of America

asked on

global replace with a variable

truncFilename = filename.substr(0,filename.lastIndexOf("."))
alert(urlPathToXdl.replace(/truncFilename/g,escape(truncFilename)))

the above replace does not work because "truncFilename" is a variable and not a string literal. if I change to:

alert(urlPathToXdl.replace(truncFilename,escape(truncFilename)))

...then the replace works but not globally (only replaces 1st instance).

How do I correctly specify the global replace?
ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial