I came across some javascript code like this:
selector = $this.attr('href')
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '')
And I don’t quite understand what the replace part do.Can someone explain that in detail?
Thanks,G
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It replaces
selectorvariable using RegEx./.*(?=#[^\s]*$)/replaces anchor to empty string and perhaps return domain name of page where you in. For example http://example.com/text.phpI’ve made and example http://jsfiddle.net/9j5Sn/