var str = this.rawValue; this.rawValue = str.replace (/\s/,"\n"); To repl The method returns a new string with all occurrences of the character replaced by the provided replacement. jquery text replace all " " with "-". Example 1: Replace All Instances Of a Character Using Regex. Find and replace every 3rd character occurrence in a given string and replace it with H Can be done in C# or regex. Inside the loop, we are using replace () method to replace the last character with an exclamation mark (! The method takes a regular expression and a replacement string as parameters and returns a new string with one or more matches replaced. ; In our case, the old_str and new_str, both will be a character. The replace () method returns a new string with the value (s) replaced.