Recently I begin to figure regular expression is really useful but hard to remember.
So this is just a tip for reviewing some basic knowledge about javascript RegExp.
First here is a link of W3school http://www.w3schools.com/jsref/jsref_obj_regexp.asp
And this link is for tesing http://www.regular-expressions.info/javascriptexample.html
if we want to find “test” in the string “give us a test and ” we can just use the javascript regex like this:
regex=test or regex =bt[a-z]+b or bt[a-z]{3}b or bt[a-z]{1,3}
First one will directly find the result of “test”. The second one will find a string with the beginning of t and followed by at least one letter between a-z. The third one is to find a string beginning with t and followed by 3 letters. The last one is to find a string beginning with t and follow by some letters. The number of letters is 1 or 2 or 3.
Beside the most important thing when we try to avoid deadly command in webpage is to check whether this is a “;” or not.
Because “;” will give the right to use another command.
When we want to execute linux command by using node.js,we need to be more careful about the security problem.Sometimes, there will be a error message like”fail to find the command”.
The best way to solve it is to use the direct path.For example: $which ssmtp
And it will show the path of that command ,then :/usr/bin/ssmtp ” + inviteEmail + ” </home/msg.txt
The command will be executed successfully.
And by the way,when we want to use regex in javascript, we should add “//”.
For example, “regex = /;/; “