The implementation code is as follows. At first, the test was normal (and then encountered a problem). First, let's look at the initial code.
Copy codeThe Code is as follows:
Var docs = document. body. innerHTML;
Var links = docs. match (/ed2k. * \ | \ // gi); // note that the dot (.) symbol is used to match any character.
Document. body. innerHTML = "";
For (var link in links) {<BR>
Document. body. innerHTML + = links [link] + "<br/>"
}
The above code is normal at first. In the next test, it is found that if the address contains full-angle characters, the matching will fail. Use the following method:
Copy codeThe Code is as follows:
Var docs = document. body. innerHTML;
Var links = docs. match (/ed2k [\ s \ S] *? \ | \ // Gi); // note that [\ s \ S]
Document. body. innerHTML = "";
For (var link in links ){
Document. body. innerHTML + = links [link] + "<br/>"
}
Conclusion, point (.) the symbol still has limitations when matching any character. The specific rules are unknown and can be replaced by [\ s \ S] for the moment, similarly, either [\ d \ D] or [\ w \ W] can be used.