Replacing is the action of searching a string for a sub-string and replacing it with a different string.
388
votes
12answers
153k views
How to replace a character for a newline in Vim?
I'm trying
:%s/,/\n/g
but it inserts what looks like a ^@ instead of an actual newline. The file is not in DOS mode or anything.
What should I do?
EDIT: If you are curious, like me, check the ...
150
votes
9answers
171k views
How to replace all periods in a string in JavaScript
I want to replace all the occurances of a period (.) in a JavaScript string
For example, I have:
var mystring = 'okay.this.is.a.string';
I want to get: okay this is a string.
So far I tried:
...
106
votes
9answers
35k views
Is there an alternative to string.Replace that is case-insensitive?
I need to search a string and replace all occurances of %FirstName% and %PolicyAmount% with a value pulled from a database. The problem is the capitalization of FirstName varies. That prevents me from ...
92
votes
9answers
52k views
Awk/Sed: How to do a recursive find/replace of a string?
How to I find and replace every occurrence of:
subdomainA.example.com
with
subdomainB.example.com
in every text file under the /home/www/ directory tree (recursive find/replace).
66
votes
8answers
88k views
Fastest method to replace all instances of a character in a string
What is the fastest way to replace all instances of a string/character in a string in Javascript? A while, a for-loop, a regular expression?
57
votes
6answers
44k views
Javascript multiple replace
How do you replace all instances of one string with another in javascript?
Example:
someString = 'the cat looks like a cat'
anotherString = someString.replace('cat', 'dog');
results in ...
56
votes
9answers
62k views
How can I perform a str_replace in Javascript?
I want to use str_replace or its similar alternative to replace some text in Javascript.
var text = "this is some sample text that i want to replace";
var new_text = replace_in_javascript("want", ...
54
votes
2answers
19k views
Regular expression search replace in Sublime Text 2
I'm looking to do search replace on regular expressions in Sublime Text 2. The documentation on this is rather anemic. Specifically, I want to do a replace on groups, so something like converting this ...
51
votes
7answers
11k views
VIM Replace word with contents of paste buffer?
I need to do a bunch of word replacements in a file and want to do it with a vi command, not an EX command such as :%s///g. I know that this is the typical way one replaces the word at the current ...
51
votes
2answers
26k views
Eclipse, regular expression search and replace
In eclipse, is it possible to use the matched search string as part of the replace string when performing a regular expression search and replace?
Basically, I want to replace all occurrences of
...
50
votes
5answers
22k views
How do I perform a Perl substitution on a string while keeping the original?
In Perl, what is a good way to perform a replacement on a string using a regular expression and store the value in a different variable, without changing the original?
I usually just copy the string ...
46
votes
9answers
37k views
How can I add a string to the end of each line in Vim?
I want to add * to the end of each line in Vim.
I tried the code unsuccessfully
:%s/\n/*\n/g
45
votes
8answers
3k views
Replace multiple <br>'s with only one <br>
How do I use JavaScript to detect
<br>
<br>
<br>
to become one
<br>
?
I tried with:
jQuery('body').html().replace(/(\<br\>\r\n){3, }/g,"\n");
but this is not ...
44
votes
7answers
8k views
Using jQuery to replace one tag with another
got a quandary i was hoping you kind folks could help me out with...
goal:
Using jQuery, I'm trying to replace all the occurrences of:
<code> ... </code>
with:
<pre> ...
44
votes
12answers
20k views
How do I replace the *first instance* of a string in .NET?
I want to replace the first occurrence in a given string.
How can I accomplish this in .NET?