<code> function palindrome(str) { return str.replace(/[\W_]/g,'').toLowerCase() === str.replace(/[\W_]/g,'').toLowerCase().split('').reverse().join(''); } palindrome("0_0 (: /-\ :) 0-0"); </code>
Why W
does not match underscore_ Doesn’t W
match non-text and numbers?
<code> function palindrome(str) { return str.replace(/[\W_]/g,'').toLowerCase() === str.replace(/[\W_]/g,'').toLowerCase().split('').reverse().join(''); } palindrome("0_0 (: /-\ :) 0-0"); </code>
Why W
does not match underscore_ Doesn’t W
match non-text and numbers?
First of all, w
matches numbers and letters underline: [0-9a-zA-Z_]
, W
is the negation of w
, that is, does not match numbers and letters underline