Home > Web Front-end > JS Tutorial > How to write regular expressions that match any character_javascript skills

How to write regular expressions that match any character_javascript skills

WBOY
Release: 2016-05-16 18:28:12
Original
1045 people have browsed it

The implementation code is as follows. The test was normal at first (later encountered problems), let’s first look at the initial code

Copy the code The code is as follows:

var docs = document.body.innerHTML;
var links =docs.match(/ed2k.*|//gi);//Note that the dot (.) symbol is used here to match any Characters
document.body.innerHTML = "";
for( var link in links){

document.body.innerHTML = links[link] "
"
}

The above code worked fine at first, but in subsequent tests it was found that if there are full-width characters in the eDonkey address, the match will fail. Then use the following writing method:
Copy the code The code is as follows:

var docs = document.body. innerHTML;
var links =docs.match(/ed2k[sS]*?|//gi);//Note here [sS]
document.body.innerHTML = "";
for( var link in links){
document.body.innerHTML = links[link] "
"
}

Conclusion, the dot (.) symbol matches any character There are still limitations, and the specific rules are unknown. For the time being, [sS] can be used instead. Similarly, [dD] or [wW] can also be used.
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template