Remova caracteres especiais da String JavaScript
var str = "Hello^# World/";
str.replace(/[^a-zA-Z ]/g, ""); // "Hello World"
TC5550
var str = "Hello^# World/";
str.replace(/[^a-zA-Z ]/g, ""); // "Hello World"
String str= "This#string%contains^special*characters&.";
str = str.replaceAll("[^a-zA-Z0-9]", " ");
System.out.println(str);
var outString = sourceString.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
function removeSpecialChar($string)
{
$string = strtolower($string);
$string = preg_replace('/[^\da-z ]/i', '', $string);// Removes special chars.
$string = str_replace(' ', '-', $string); // Replaces all spaces with underscore.
return strtolower($string);
}
#include <iostream>
#include <string>
#include <algorithm>
int main()
{
std::string s = "#Hello #World!!";
std::string chars = "#!";
for (char c: chars) {
s.erase(std::remove(s.begin(), s.end(), c), s.end());
}
std::cout << s;
}