Enter a string
your string
match character a
anywhere
search found first a
at location
replace all a
with A
// sample-6-regular-expressions.js // This sample shows String character methods function reset_values() { var output1 = document.getElementById("output1"); var output2 = document.getElementById("output2"); var output3 = document.getElementById("output3"); var output4 = document.getElementById("output4"); var output5 = document.getElementById("output5"); output1.value = null; output2.value = null; output3.value = null; output4.value = null; output5.value = null; output1.focus(); } function change_values() { var output1 = document.getElementById("output1"); var output2 = document.getElementById("output2"); var output3 = document.getElementById("output3"); var output4 = document.getElementById("output4"); var output5 = document.getElementById("output5"); var string_object = new String(output1.value); output2.value = string_object; var a_pattern = new RegExp("a","i"); // a, case insensitive if (string_object.match(a_pattern) != null) output3.value = "yes"; else output3.value = "no"; var string_location = string_object.search(a_pattern); if (string_location != -1) output4.value = string_location; else output4.value = "none"; var global_a_pattern = new RegExp("a","g"); // a, case sensitive, global var replaced_string = string_object.replace(global_a_pattern, "A"); output5.value = replaced_string; }