admin管理员组文章数量:1289703
I have to validate the local folder path which is in the following format : ..\sentinel\log .
I have old regular expression ( /[\w]:\.*/)) for C:\sentinel\log and that was working. I need to make accept this path.
I have the following expresion from regexplibrary
var pathRE = new RegExp("/^((../|[a-zA-Z0-9_/-\])*.[a-zA-Z0-9])"); Error : SyntaxError: unterminated parenthetical
When i executing is throw this error
I am attaching the code that i have tried
function checkFolderpath(path) {
try {
//var pathRE = new RegExp(/[\w]:\\.*/);
var pathRE = new RegExp("/^((\.\./|[a-zA-Z0-9_/\-\\])*\.[a-zA-Z0-9])");
if (pathRE.test(path)) {
$("#spanloggererror").html("");
return true;
}
else {
$("#spanloggererror").html(resx_Invalid_Loggerpath);
valtemp = 1;
}
return false;
}
catch (err) {
alert(err.Message);
}
Please suggest me how to fix the issue.
Edit :
value of path : ..\Sentinel\log
I have to validate the local folder path which is in the following format : ..\sentinel\log .
I have old regular expression ( /[\w]:\.*/)) for C:\sentinel\log and that was working. I need to make accept this path.
I have the following expresion from regexplibrary
var pathRE = new RegExp("/^((../|[a-zA-Z0-9_/-\])*.[a-zA-Z0-9])"); Error : SyntaxError: unterminated parenthetical
When i executing is throw this error
I am attaching the code that i have tried
function checkFolderpath(path) {
try {
//var pathRE = new RegExp(/[\w]:\\.*/);
var pathRE = new RegExp("/^((\.\./|[a-zA-Z0-9_/\-\\])*\.[a-zA-Z0-9])");
if (pathRE.test(path)) {
$("#spanloggererror").html("");
return true;
}
else {
$("#spanloggererror").html(resx_Invalid_Loggerpath);
valtemp = 1;
}
return false;
}
catch (err) {
alert(err.Message);
}
Please suggest me how to fix the issue.
Edit :
value of path : ..\Sentinel\log
Share Improve this question asked Sep 26, 2013 at 14:01 Thangamani PalanisamyThangamani Palanisamy 5,3004 gold badges35 silver badges39 bronze badges 2- what is the value of path – Arun P Johny Commented Sep 26, 2013 at 14:02
-
The
/
is an issue at the start – epascarello Commented Sep 26, 2013 at 14:03
2 Answers
Reset to default 6Your regular expression should be constructed like this:
var pathRE = /^((..\/|[a-zA-Z0-9_/-\\])*.[a-zA-Z0-9])/;
The only time you really need to use the RegExp constructor is when you're building up a regular expression from separate pieces, dynamically. You have to be careful with quoting forward-slash characters in the expression (/
) when you use native regular expression syntax. You don't have to quote them inside [ ]
groups, but you do need to double your backslashes.
That regular expression won't match ..\what\ever
because it only looks for forward slash at the start. It also won't match a terminal file name longer than two characters. I think a better one would be:
var pathRE = /^\.\.(?:\\[A-Za-z0-9_-]+)+/;
with appropriate changes for the file name characters you expect.
Escape the slash:
/^((\.\./|[a-zA-Z0-9_\/\-\\])*\.[a-zA-Z0-9])/
// here __^ and add slash __^
本文标签: javascriptSyntaxError unterminated parenthetical for validating the local file pathStack Overflow
版权声明:本文标题:javascript - SyntaxError: unterminated parenthetical for validating the local file path - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741427383a2378155.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论