Regex issues

I have the following truncation expression and it’s replacing everything when tripped–even anchor code.


trunc = trunc.replace(/\\w+$/, '');

What can I do to make it ignore the code that’s used for anchor tags?

Hi,
I’m not absolutely sure what you are asking for
but I’ll have a try :slight_smile:


var trunc = 'fffff#?ffffffff';
trunc = trunc.replace(/[a-z#]+$/, '');
// trunc == fffff#?

I hope this can help.
Bye.

as per the MDC Regex documentation:

\w
Matches any alphanumeric character from the basic Latin alphabet, including the underscore. Equivalent to [A-Za-z0-9_].

For example, /\w/ matches ‘a’ in “apple,” ‘5’ in “$5.28,” and ‘3’ in “3D.”

What is it you’re trying to do? Truncate white space from the end of a string?

If so, you’ll probably want to use \s instead.