The solution is as follows:
Copy codeThe Code is as follows:
Content. replace (/] * src = ['"] ([^'"] +) [^>] *>/gi, function (match ){
Console. log (match );
});
The output result is:
Copy codeThe Code is as follows:
The entire img tag is obtained, but what I expect is the URL in src, so you only need to return the new address in function (match.
So, it's stuck here...
Later, Google searched for the keyword "javascript replace callback" and found "replace callback function with matches" in stackoverflow to know that function (match) has other parameters.
Then, change the code below to solve the problem.
Copy codeThe Code is as follows:
Content. replace (/] * src = ['"] ([^'"] +) [^>] *>/gi, function (match, capture ){
Console. log (capture );
});
Output result:
Copy codeThe Code is as follows:
Http://www.bkjia.com/uploads/allimg/131230/0300101S7-0.gif