eq******@gmail.com wrote:
Hello, this sentence is from the Ajax.Request.prototype function in
prototype.js:
this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;
I understand what it does but I don't know how does "/\?/" work. Would
it be the same as "this.url.match('?')" ?
- What is each slash for?
- Is "\?" an escape character?
Can anybody help me?
Carlos from Barcelona.
Hi Carlos
Its a regular expression, broken down
/ is the start of the expression
\? match a question mark anywhere in the url
/ is the end of the expresssion.
the \ is an escape character because ? on its own means something
else entirely.
Regular expressions are a very powerful tool for matching patterns
in strings. There is plenty of info on the web about them and
one here.
http://www.sitepoint.com/article/exp...s-javascript/2
HTH
Chris