replace espacial characteres from string

Solutions on MaxInterview for replace espacial characteres from string by the best coders in the world

showing results for - "replace espacial characteres from string"
Marion
15 Jun 2019
1function convertHtmlToText() {
2    var inputText = document.getElementById("input").value;
3    var returnText = "" + inputText;
4
5    //-- remove BR tags and replace them with line break
6    returnText=returnText.replace(/<br>/gi, "\n");
7    returnText=returnText.replace(/<br\s\/>/gi, "\n");
8    returnText=returnText.replace(/<br\/>/gi, "\n");
9
10    //-- remove P and A tags but preserve what's inside of them
11    returnText=returnText.replace(/<p.*>/gi, "\n");
12    returnText=returnText.replace(/<a.*href="(.*?)".*>(.*?)<\/a>/gi, " $2 ($1)");
13
14    //-- remove all inside SCRIPT and STYLE tags
15    returnText=returnText.replace(/<script.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/script>/gi, "");
16    returnText=returnText.replace(/<style.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/style>/gi, "");
17    //-- remove all else
18    returnText=returnText.replace(/<(?:.|\s)*?>/g, "");
19
20    //-- get rid of more than 2 multiple line breaks:
21    returnText=returnText.replace(/(?:(?:\r\n|\r|\n)\s*){2,}/gim, "\n\n");
22
23    //-- get rid of more than 2 spaces:
24    returnText = returnText.replace(/ +(?= )/g,'');
25
26    //-- get rid of html-encoded characters:
27    returnText=returnText.replace(/ /gi," ");
28    returnText=returnText.replace(/&/gi,"&");
29    returnText=returnText.replace(/"/gi,'"');
30    returnText=returnText.replace(/</gi,'<');
31    returnText=returnText.replace(/>/gi,'>');
32
33    //-- return
34    document.getElementById("output").value = returnText;
35}
36