Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
78
rated 0 times [  80] [ 2]  / answers: 1 / hits: 21556  / 6 Years ago, tue, march 6, 2018, 12:00:00

Say, I have a text stored as:



var val1 = 'l-oreal';


I want to match val1 such that, it reads val1 and ignores hyphen (dash) in it. I want a regex that ignores special characters in a text. Is that possible?



I don't want to remove special character from the text. I want to ignore it.


More From » regex

 Answers
16

You can match against the regex /[a-z]+/gi and then join by a space or any other character:





var testString = any string l-orem;
var matcher = /[a-z]+/gi;
var matches = testString.match(matcher);
var result = matches.join('');
console.log(result);





This, of course, doesn't change your original string, and can be simply customized to your own needs.


[#55005] Thursday, March 1, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kareem

Total Points: 733
Total Questions: 110
Total Answers: 102

Location: Bermuda
Member since Thu, Apr 20, 2023
1 Year ago
;