php replace ' \' code example

Example 1: javascript replace string

var str = "JavaScript replace method test";
var res = str.replace("test", "success");  
//res = Javscript replace method success

Example 2: javascript remove text from string

var str = "That is like so not cool, I was like totally mad.";
var cleanStr = str.replace(/like/g, "");//replace every "like" with blank ""

Example 3: js replace characters in a string

var str = "Original string!";
var str = str.replace("Original", "New");

Example 4: javascript replace

var res = str.replace("find", "replace");

Example 5: python replace

string = "[Message]"
string = string.replace("[", "")#Removes all [
string = string.replace("]", "")#Removes all ]

print(string)

Example 6: python replace "\" for "/"

my_string = r'\\ServerA\DriveB\5.FolderC\A.TXT'
my_string = my_string.replace('\\', '/')

Tags: