Removing soft hyphens from a string

Say I have a line filled with soft hyphens (pretend that the hyphens in the text below are soft hyphens):

T-h-i-s- -i-s- -a- -t-e-s-t-.-

I want to remove soft hyphens and return a string:

This is a test.

I am trying to do this in JavaScript. Below is the farthest way I've got so far:

RemoveSoftHyphen: function (text) {
    var result = text.match(/[^\uA00AD].*/);
    alert (result);
    return result;
}

When the warning appeared, all I got was a “-”, and I'm not sure if this is a soft or hard hyphen ... but more importantly, it did not work.

I'm trying to figure out what is wrong with my regex, or is there a better approach to removing soft hyphens that I don't know about using JavaScript or jQuery.

+3
source share
1 answer

Assuming the character is indeed Unicode 00AD:

var result = text.replace(/\u00AD/g,'');

, , :

var result = text.replace(/[\u00AD\u002D\u2011]+/g,'');
+9

All Articles