{"id":48151,"date":"2020-03-02T03:01:48","date_gmt":"2020-03-01T17:01:48","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=48151"},"modified":"2020-02-29T10:11:37","modified_gmt":"2020-02-29T00:11:37","slug":"javascript-replace-regexp-multiline-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-replace-regexp-multiline-primer-tutorial\/","title":{"rendered":"Javascript Replace RegExp Multiline Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/javascript_regex_multiline.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Javascript Replace RegExp Multiline Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/javascript_regex_multiline.jpg\" title=\"Javascript Replace RegExp Multiline Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Javascript Replace RegExp Multiline Primer Tutorial<\/p><\/div>\n<p>Lately we have had a couple of web application projects using HTML <a target=_blank title='HTML textarea information from w3schools' href='http:\/\/www.w3schools.com\/tags\/tag_textarea.asp'>textarea<\/a> elements extensively.  When you involve this particular HTML element type ascii code 10 (line feed) comes into play, and we, as programmers, may need to contend with &#8230;<\/p>\n<p><code><br \/>\nmultiline data<br \/>\n<\/code><\/p>\n<p> &#8230; in this scenario.  It&#8217;s easy enough to use Javascript <a target=_blank title='Javascript string replace function information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/jsref_replace.asp'>replace<\/a> function combined with <a target=_blank title='Javascript RegExp information from w3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_obj_regexp.asp'>regular expressions<\/a> (RegExp) to simulate for a var<font size=1>iable<\/font> x what x.<a target=_blank title='String trim function information from w3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_trim_string.asp'>trim<\/a>() does for a single line of string data (with no ascii code 10 nor 13), as per &#8230;<\/p>\n<p><code><br \/>\nvar outstr = x.replace(\/^\\s+|\\s+$\/g,'');<br \/>\n<\/code><\/p>\n<p> &#8230; but I&#8217;d never used, nor thought to use, the Javascript replace function combined with regular expressions to trim a whole paragraph of string data, as you might find resulting from the use of an HTML textarea element.  We&#8217;d like to thank <a target=_blank href='https:\/\/stackoverflow.com\/questions\/49209362\/what-is-the-meaning-of-s-s-gm-in-javascript' title='Useful link, thanks'>this great link<\/a>, for the heads up, in this regard, used in this Javascript function <font color=blue>(suitable for multiline string data)<\/font>  &#8230;<\/p>\n<p><code><br \/>\n function myTrim(x) {<br \/>\n  return x.replace(\/^\\s+|\\s+$\/g<font color=blue>m<\/font>,'');<br \/>\n }<br \/>\n<\/code><\/p>\n<p> &#8230; used in today&#8217;s HTML and Javascript <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/javascript_regex_multiline.html_GETME\" title=\"javascript_regex_multiline.html\">javascript_regex_multiline.html<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/javascript_regex_multiline.html\" title=\"Click picture\">proof of concept web application<\/a> below can show you this in action &#8230;<\/p>\n<p><iframe src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/javascript_regex_multiline.html\" style=\"width:100%;height:720px;\"><\/iframe><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d48151' onclick='var dv=document.getElementById(\"d48151\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/replace\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d48151' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Lately we have had a couple of web application projects using HTML textarea elements extensively. When you involve this particular HTML element type ascii code 10 (line feed) comes into play, and we, as programmers, may need to contend with &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-replace-regexp-multiline-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[576,652,2533,3241,1825,997,1040,2226,1043,1053,1626,3242,1319,1721],"class_list":["post-48151","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-html","tag-javascript","tag-line-feed","tag-multiline","tag-paragraph","tag-programming","tag-regex","tag-regexp","tag-regular-expression","tag-replace","tag-string","tag-trim","tag-tutorial","tag-variable"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/48151"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=48151"}],"version-history":[{"count":10,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/48151\/revisions"}],"predecessor-version":[{"id":48161,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/48151\/revisions\/48161"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=48151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=48151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=48151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}