Home > Backend Development > PHP Tutorial > javascript - Questions about regular expressions

javascript - Questions about regular expressions

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-09-23 11:31:05
Original
1006 people have browsed it

<code>       function palindrome(str) {
         return str.replace(/[\W_]/g,'').toLowerCase() === str.replace(/[\W_]/g,'').toLowerCase().split('').reverse().join('');
        }
    
  palindrome("0_0 (: /-\ :) 0-0");
</code>
Copy after login
Copy after login

Why W does not match underscore_ Doesn’t
W match non-text and numbers?

Reply content:

<code>       function palindrome(str) {
         return str.replace(/[\W_]/g,'').toLowerCase() === str.replace(/[\W_]/g,'').toLowerCase().split('').reverse().join('');
        }
    
  palindrome("0_0 (: /-\ :) 0-0");
</code>
Copy after login
Copy after login

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

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template