Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a JavaScript function extractContent(str) that extracts the text content from given HTML fragment
- (given as string). The function should return anything that is in a tag, without the tags.
- Write JS program contentExtracter.js that invokes your function with the sample input data below
- and prints the output at the console. */
- "use strict";
- function extractContent(str) {
- var pattern = />[^<]+/g;
- var matcher;
- var contentArr = [];
- while ((matcher = pattern.exec(str)) !== null) {
- var content = matcher[0].replace(/^>/, '');
- contentArr.push(content);
- }
- console.log(contentArr.join(''));
- }
- extractContent("<p>Hello</p><a href='http://w3c.org'>W3C</a>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement