She*_*lam 10 javascript regex string
我希望能够检测字符串是否有.在其中并基于此返回true/false.
例如:
"myfile.doc" = TRUE
Run Code Online (Sandbox Code Playgroud)
与
"mydirectory" = FALSE;
Run Code Online (Sandbox Code Playgroud)
Ali*_*guy 31
使用 indexOf()
var str="myfile.doc";
var str2="mydirectory";
if(str.indexOf('.') !== -1)
{
// would be true. Period found in file name
console.log("Found . in str")
}
if(str2.indexOf('.') !== -1)
{
// would be false. No period found in directory name. This won't run.
console.log("Found . in str2")
}Run Code Online (Sandbox Code Playgroud)