如何检查字符串在JavaScript中是否为文件路径?

问题描述 投票:0回答:1

我想检查给定的字符串是否是PHP文件的文件路径,但失败了。 :(

// function: is string a path to PHP file?

var isFilepath = str =>(
  /^[a-z]:((\\|\/)[a-zA-Z0-9\s_@\-^!#$%&+={}\[\]]+)+\.php$/i.test(str)
);

// example how I am actually trying to apply it

var str = '../lib/ajax/pDetails.php';

if( isFilepath(str) ){
  console.log('Yes, it is a filepath.');
}
javascript regex string function filepath
1个回答
0
投票

也许,

© www.soinside.com 2019 - 2024. All rights reserved.