{"id":39668,"date":"2018-08-29T03:01:07","date_gmt":"2018-08-28T17:01:07","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=39668"},"modified":"2018-08-29T10:15:31","modified_gmt":"2018-08-29T00:15:31","slug":"javascript-replace-regex-eval-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-replace-regex-eval-primer-tutorial\/","title":{"rendered":"Javascript Replace RegEx Eval Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/regex_eval.html\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Javascript Replace RegEx Eval Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/regex_eval.jpg\" title=\"Javascript Replace RegEx Eval Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Javascript Replace RegEx Eval Primer Tutorial<\/p><\/div>\n<p>Until I saw <a target=_blank title='https:\/\/stackoverflow.com\/questions\/1162529\/javascript-replace-regex' href='\/\/stackoverflow.com\/questions\/1162529\/javascript-replace-regex'>this great link<\/a>, thanks, I&#8217;d cut off the thought of combining &#8230;<\/p>\n<ul>\n<li><a target=_blank title='Javascript string replace function information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/jsref_replace.asp'>replace<\/a> Javascript method &#8230; using for the first parameter &#8230;<\/li>\n<li>a regular expression (&#8220;<a target=_blank title='Javascript regex' href='http:\/\/www.w3schools.com\/jsref\/jsref_obj_regexp.asp'>RegEx<\/a>&#8221; in our terminology today) &#8230; meaning &#8220;replace all&#8221; as distinct from the default &#8220;replace first once&#8221; &#8230; with &#8230;<\/li>\n<li><a target=_blank title='Javascript eval function information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/jsref_eval.asp'>eval<\/a> Javascript method &#8230; to effectively &#8220;calculate after the event&#8221;<\/li>\n<\/ul>\n<p>But this combination can be powerful, as you might imagine.  It means a dynamically determined pattern match can be placed in a Javascript var<font size=1>iable<\/font> and become that first parameter to the Javascript replace call via Javascript eval or that first parameter can be just part of a complex &#8220;total replace method call&#8221; like we construct today with <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/regex_eval.html_GETME\" title=\"regex_eval.html\">regex_eval.html<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/regex_eval.html\" title=\"Click picture\">live run<\/a> link.  This could be a boon to global substitution programming requirements you encounter with the client side of web applications.<\/p>\n<p>Some other techniques we get more and more fond of as time goes on used in this &#8220;proof of concept&#8221; web application are &#8230;<\/p>\n<ul>\n<li>use of HTML div <a target=_blank title='HTML contenteditable attribute information from w3schools' href='https:\/\/www.w3schools.com\/tags\/att_global_contenteditable.asp'>contenteditable<\/a>=true (attributed) elements for ease of use for the user entering in the <em>three parts<\/em> to the Javascript &#8230;<br \/>\n<code><br \/>\n[Resultant String] = <em>[Original String]<\/em>.replace(<em>[RegEx Pattern From]<\/em>, <em>\"String To\"<\/em>);<br \/>\n<\/code>\n<\/li>\n<li>use of String.<a target=_blank title='Javascript string methods from w3schools' href='https:\/\/www.w3schools.com\/js\/js_string_methods.asp'>fromCharCode<\/a>(10) and String.fromCharCode(39) at times when the delimitation just gets too tough<\/li>\n<\/ul>\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='#d39668' onclick='var dv=document.getElementById(\"d39668\"); dv.innerHTML = \"<iframe width=670 height=600 src=\" + \"\/\/www.rjmprogramming.com.au\/ITblog\/tag\/replace\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d39668' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Until I saw this great link, thanks, I&#8217;d cut off the thought of combining &#8230; replace Javascript method &#8230; using for the first parameter &#8230; a regular expression (&#8220;RegEx&#8221; in our terminology today) &#8230; meaning &#8220;replace all&#8221; as distinct from &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-replace-regex-eval-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":[2442,2276,2147,342,399,2142,576,652,997,1040,2226,1043,1053,1626,1206,1319],"class_list":["post-39668","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-contenteditable","tag-delimitation","tag-delimiter","tag-div","tag-eval","tag-global-substitution","tag-html","tag-javascript","tag-programming","tag-regex","tag-regexp","tag-regular-expression","tag-replace","tag-string","tag-string-functions","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/39668"}],"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=39668"}],"version-history":[{"count":6,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/39668\/revisions"}],"predecessor-version":[{"id":40431,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/39668\/revisions\/40431"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=39668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=39668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=39668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}