, , :
if ( req.headers.host.search(/^www/) !== -1 ) {
res.redirect(301, "http://example.com/");
}
The search method takes a regular expression as the first argument, denoted by surrounding slashes. The first character, ^, in the expression means to explicitly see the beginning of the line. The rest of the expression searches for three explicit w. If the line starts with "www", then the search method returns a match index if it is (0) or -1 if it was not found.
source
share