0

what's wrong with match() in javascript ?

var path = "D:\Programs\DeveloperTools";
var patt=/.+\\/g;
alert(path.match(patt));

The Result Should Be : D:\Programs\

2
  • 4
    When I first read this, I couldn't help but think you were very sad about your Programs directory. Commented May 2, 2011 at 21:28
  • Nothing's wrong with it. The real question is, what's wrong with your Javascript usage? Commented May 2, 2011 at 21:58

1 Answer 1

5

Escape:

var path = "D:\\Programs\\DeveloperTools";

Now match and alert the path and you will get the expected result. And here's the live demo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.