Convert string to RegExp pattern?
Hi,
I have an input box that requests a path and want to convert it to a
pattern so it can be used by a RegExp.
e.g. I have a string "d:\\" and want to make it into a pattern. The
RegExp pattern is "d\:\\\\" (arrrrrh).
(It seems you can do it the other way round using the source properly of
the RegExp)
The reason I want this is so I can extract a relative path from an
absolute path, for example:
Full path is
"d:\\testfolder\\very\\deep\\folder\\structure\\myFile.xyz"
and I want to replace "d:\\testfolder" with "f:\\test2" so the final
path is
"f:\\test2\\very\\deep\\folder\\structure\\myFile.xyz"
The replace method seemed like a good way to do this, and works fine if
all the paths are hard coded, but when you want to obtain the path from
elsewhere, it seems you need a way to convert it to a pattern.
--
Gerry Hickman (London UK)