Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let pattern = /<a [^>]+>([^<]+)<\/a>/g;
- let matches = input[0].match(pattern);
- for (let match of matches){
- let hrefPattern = /"((?:\\.|[^"\\])*)"/g;
- let href = match.match(hrefPattern)[0];
- href = href.substr(1, href.length - 2);
- let startIndex = match.indexOf('>', 1) + 1;
- let endIndex = match.indexOf('<', 1);
- let link = match.substring(startIndex, endIndex);
- let result = `[${link}](${href})`;
- console.log(match);a
- console.log(result);
- input[0].replace()
- }
- console.log(input[0]);
- }
- solve(['<p>Please visit <a href="http://academy.telerik.com">our site</a> to choose a training course. Also visit <a href="www.devbg.org">our forum</a> to discuss the courses.</p>']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement