javascript - Returning true for strings that begin with a hashtag using regex -


i'm confused why in http://regexr.com/3bcns, ^# isn't matching #hello-link, string begins hashtag.

this want do:

if ((/^\.\./).test(link)) {  alert('link starts ..'); } else if (!(/#/).test(link)) { alert('does not contain #'); } else if ((/^#/).test(link))  {  alert('link begins #'); } 

also, i'm curious: there reason why people prefer use .test instead of .match when using regexes in javascript?

why not check first character of string?

function start_with_hash(str){   return str[0]=='#'; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -