"Danny" wrote
den wrote:
>var newstring = oldstring.replace( /[^\w_-]/g, '' );
in this example you use
w_- if I want other at characters a-zA-Z0-9 also the undersscore _
and -;
but inner w is there underscore _ , or is preferable however to rewrite
it
outside for greater compatibility (particular version of javascripts,
browser, et cetera .. ?
No, is fine on that line for me :). I'd bother on using a variable for
the
regex only if it's rather long or needs to be changed/updated/modified
during
the runtime.
You 're right, den. The underscore character does not need to be explicitly
mentioned since the metacharacter \w covers it already. There was some
uncertainly in the past about this, but I am not aware now of any JS1.2
browser that fails here. Still, it does not do much harm in the expression.
And no, creating a variable regex is not necessary in this script.
hth
ivo