DbZ wrote:
Hi - i'm new to the regex thing - and trying to learn it to myself -
I can very much recommend reading the two free sample chapters of Mastering
Regular Expressions First and Second Edition by Jeffrey E. F. Friedl at
O'Reilly Online. And probably the book is worth buying.
http://www.oreilly.com/catalog/regex/ pp.
Can someone please explain to me what the following line does -
value.replace(/\s+$/g,"")
I can kinda figure out its replacing a something with an empty space -
on a global search. But thats about it
It is replacing one or more consecutive (`+') whitespace (`\s') at the end
(`$') of the string `value' with the empty string (`""', i.e. removing the
matched substring) and returns the result. (The `g'lobal flag which would
make the expression to apply to *every* match, not only the first one, is
therefore unnecessary here; there can be only one match because the
expression is anchored by `$'.)
For the above to have effect, you would need to assign the result to
something, for example:
value = value.replace(/\s+$/, "");
HTH
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>