2
I have an algorithm that takes several complete file paths and checks if each of them is 'forbidden' by the server.
The var s
of for
is related to each of these paths and the sets
is an array with regular expressions to be checked.
The problem is that, for example, if I have 4 named files from aq, aq2, aq3 and aq4 and set in array
that I want to probidir only the aq and aq4, all will be probidios... hence the term needs to be exact.
I also could not use Regex literal with value of sets[s]
so I want to know how to do this using constructor syntax.
var sets = ['contatos/aq', 'contatos/aq4'];
for(var s=0; s < sets.length; s++) {
var comst =
if( new RegExp(sets[s]).test(path_p) ) { // se arquivo for proibido pelo sets...
if(testheader.test(read) && testfooter.test(read)){
read = read.replace(testheader, '');
read = read.replace(testfooter, '');
fs.writeFileSync(totxt, read);
}
fs.renameSync(totxt, path_p);
return false;
}
}
My impression, or is your code incomplete? What is this
var comst =
Loose there on the 4° line?– Fernando Leal
One-eyed here I touched a few things and did some tests and apparently simply is working, check if it helps you.
– Fernando Leal
@Fernando I made a small mistake: the files are actually aq, aq2, aq3 and aq4. I’ve already edited. Understand why it has to be an exact Regex now?
– ropbla9
When you say exact you say:
'contatos/aq' == 'contatos/aq'
?– Fernando Leal
@Fernando that same.
– ropbla9
Then do a simple check, no regular expression, of a look therein. That’s the way it is?
– Fernando Leal
@Fernando It turns out that the complete paths are more or less like this: __dirname/folder/subfolder/home/contacts/aq.ejs
– ropbla9
I did it the way you said it from one look here, if that is the case let me know that I have prepared a response explaining in more detail the solution.
– Fernando Leal