Wednesday, January 22, 2014

Regular Expression


Following is a javascript function using regex to convert HTML BR tags to "\n" new lines.


function replaceHTMLBR(inputMesg) {

var retMesg = inputMesg.replace(/(<br\s*[\/]?>)|(&lt;br\s*[\/]?&gt;)/ig, "\n");
return retMesg;


}


I found this website very useful to check syntax errors of regular expression.

http://regex101.com/#Javascript