Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a JavaScript function replaceATag(str) that replaces in a HTML document given as string
- all the tags <a href="…">…</a> with corresponding tags [URL=…]…/URL]. Write JS program aTagReplacer.js
- that invokes your function with the sample input data below and prints the output at the console. */
- "use strict";
- function replaceATag(str) {
- var pattern = /<a\s([^>]+)>([^<]+)<\/a>/g;
- var matcher = pattern.exec(str);
- var replacedString = '[URL ' + matcher[1] + ']' + matcher[2] + '[/URL]';
- console.log(str.replace(matcher[0], replacedString));
- }
- replaceATag(
- "<ul>" +
- "<li>" +
- "<a href = http://softuni.bg>SoftUni</a>" +
- "</li>" +
- "</ul>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement