Tag Archive for replace

Replace string in multiple files

sed -i 's#old#new#gi' **/*.suffix

source

Replace _ with – in almost every url (plus nice tag urls in movabletype)

RewriteEngine On
RewriteRule ^tag/?$ /browse.html [L]
RewriteRule ^tag/(.*)$ /mt/mt-search.cgi?tag=$1&blog_id=1&IncludeBlogs=1 [L]
RewriteRule ^mt-static(.*)$ - [L]
RewriteRule ^(.*)_(.*)$ $1-$2 [N]

source

Replace Text

function replaceText( field:TextField, toSearch:String, toReplace:String)
{
return field.split(toSearch).join(toReplace);
};

trace(replaceText(display_txt.text, "a", "b"));

source

MySQL Mass Text/String Replace

UPDATE table_name SET column = REPLACE(column, 'old_text', 'new_text');

source

Image Replace for Buttons

#submitButton {
width: 38px;/* Width of button image */
height: 19px;/* Height of button image */
padding: 30px 0 0;
margin: 0;
border: 0;
background: transparent url(images/buttonimage.gif) no-repeat;
overflow: hidden;
cursor: pointer; /* hand-shaped cursor */
cursor: hand; /* for IE 5.x */
}

source

Regular expressions filename replace

// This will strip out any punctuation and spaces from filenames, replacing such characters with underscores
$filename = preg_replace("/[^a-zA-Z0-9s.]/", "_", $filename);

source

str_replace

	function str_replace( search, replace, string ):String{
var array = string.split(search);
return array.join(replace);
}

source

Search and replace text in a string

var newText:String = "The rain in Spain falls mainly on the plain";
var splitText:Array = newText.split("Spain");
newText = splitText.join("Barcelona");
// outputs "The rain in Barcelona falls mainly on the plain"

source

search and replace across multiple files with Perl

#print the result of search-and-replace to the terminal
perl -pe 's/bart/milhouse/g' test.html

#search-and-replace, with backup
#leave the suffix off of -i to overwrite
perl -i.bak -pe 's/bart/milhouse/g' test.html

#echo the number of lines in a file
perl -lne 'END { print $t } @w = /(w+)/g; $t += @w' test.html

#cat file with line numbers
# -p prints $_ each iteration
perl -pe '$_ = "$. = $_"' test.html

# recursive search-and-replace, only on shells that support file globs
perl -i.bak -pe 's{bart}{milhouse}' **/*html

source

String.replaceAll method implementation

String.prototype.replaceAll = function(pcFrom, pcTo){
var i = this.indexOf(pcFrom);
var c = this;

while (i > -1){
c = c.replace(pcFrom, pcTo);
i = c.indexOf(pcFrom);
}
return c;
}

source