Removing soft hyphens from a string

后端 未结 1 1368
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 03:26

Let\'s say I have a string that is littered 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-.-
<         


        
相关标签:
1条回答
  • 2021-01-13 03:55

    Assuming that the character really is Unicode 00AD:

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

    If you have many hyphens to kill, use a character class:

    var result = text.replace(/[\u00AD\u002D\u2011]+/g,'');
    
    0 讨论(0)
提交回复
热议问题