javascript - 将 URI 转换为 Windows 路径格式

标签 javascript uri

在 Javascript 中,我正在寻找将 URI 转换为 Windows 格式的正则表达式,但我不太熟悉 URI 的大小写以形成正则表达式。 基本上...

  • /c/myDocs/file.txt
  • //myDocs/file.txt

应该改为

"C:\myDocs\file.txt"

可能还有其他我不知道的情况。因此需要一些帮助。到目前为止,我所要做的就是用替换替换斜杠,而不是用正则表达式替换驱动器名称。

function pathME(apath)
{
    apath = apath.replace(/\//g, "\\")
    return apath;
}

正则表达式向导,请启动您的引擎!

最佳答案

这将涵盖上述两种情况:

mystring.replace(/^\/([^\/]?)\//, function(match, drive) {
    return (drive || 'c').toUpperCase() + ':\\';
}).replace(/\//g, '\\');

关于javascript - 将 URI 转换为 Windows 路径格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15089165/

相关文章:

javascript - 正确加载顺序 javascript 文件

java - File.toURI 不编码加号

Perl从html文件中提取模式

.net - 资源图片的绝对UriSource

php - mod_rewrite & PHP; $_SERVER ['REQUEST_URI'] 与 mod_rewrite

javascript - gulp 在文件夹中搜索 src 并保存到父文件夹

javascript - setInterval导致内存溢出?

php - JSON 错误 : parsererror

javascript - nodejs express 应用程序不会返回 json 数组

java - ContentUris.withAppishedId 和 Uri.buildUpon().appendPath 之间的区别