Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
186
rated 0 times [  188] [ 2]  / answers: 1 / hits: 32598  / 9 Years ago, wed, february 10, 2016, 12:00:00

My code is:



var result2 = result.replace(/[W_]/g,).replace(,,).replace(.,);


The code works i get what i need done, but I don't understand how the regular expression /[W_]/g works, and I can't find any documentation that i understand.


More From » regex

 Answers
179

/ ... /g It's a global regex. So it'll operate on multiple matches in the string.

[ ... ] This creates a character set. Basically it'll match any single character within the listed set of characters.

W_ This matches the inverse of word characters and underscores. Any non-word character.



Then you have a few one off replacements for comma and period. Honestly, if that's the complete code, /[W_,.]/g, omitting the two other replaces, would work just as well.


[#63359] Tuesday, February 9, 2016, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
myrap

Total Points: 407
Total Questions: 105
Total Answers: 109

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
myrap questions
Tue, Feb 8, 22, 00:00, 2 Years ago
Wed, Jan 15, 20, 00:00, 4 Years ago
Thu, Oct 24, 19, 00:00, 5 Years ago
Thu, Oct 3, 19, 00:00, 5 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;