Dúvida como usar o replace do JavaScript


23-01-2003
Dúvida como usar o replace do JavaScript
Bom dia.
Amigos vocês sabem como fazer isso por exemplo


Código:
<script> var teste = new String("testeteste"); document.write("Teste : " + teste.replace("t","")); </script>



Oque acontece ele somente da replace no primeiro t ficando
Teste : esteteste Mais quero substituir todos os t tem que usar expressões regulares mais não sei como fazer vocês podem me ajudar?

[]s
25-01-2003
Acontece que esse método utiliza expressão regular...
o correto seria fazer:

Código:
<script> var teste = new String("testeteste"); document.write("Teste : " + teste.replace(/t/g,"")); </script> MyStr = "ABCDE 12345 HIJKL 67890"; MyStr.match(\d); // retorna 1 MyStr.match(\D); // retorna A MyStr.match(\w); // retorna A MyStr.match(\W); // retorna 1 MyStr.match(\s); // retorna o primeiro espaço MyStr.match(\S); // retorna A MyStr.match(\b); // não retorna nada (apenas verifica) MyStr.match(\B); // não retorna nada (apenas verifica) MyStr.match(\.); // retorna A MyStr = "ABCDE 12345 HIJKL 67890"; MyStr.match(/[a-z]/); // não retorna nada (todas as letras são maiúsculas) MyStr.match(/[A-Z]/); // retorna A MyStr.match(/[^A-Z]/); // retorna o primeiro espaço MyStr.match(/[0-9]/); // retorna 1 MyStr.match(/[^0-9]/); // retorna A MyStr.match(/[A]/); // retorna A MyStr.match(/[CXYZ]/); // retorna C MyStr.match(/[^CXYZ]/); // retorna A MyStr = "ABCDE 12345 HIJKL 67890"; MyStr.match(/[A-Z]*/); // retorna ABCDE MyStr.match(/[A-Z]+/); // retorna ABCDE MyStr.match(/[A-Z]?/); // retorna A MyStr.match(/[A-Z]{2}/); // retorna AB MyStr.match(/[A-Z]{2,}/); // retorna ABCDE MyStr.match(/[A-Z]{2,5}/); // retorna ABCDE MyStr = "ABCDE 12345 HIJKL 67890"; x = MyStr.match(/\w\w\w/g); // retorna ABC, 123, HIJ, 678 x = MyStr.match(/\w\w\w/); // retorna ABC x = MyStr.match(/abc/i); // retorna ABC
 
Guia do Hardware Melhores Tópicos