AngularBoy AngularBoy - 1 month ago 10
Javascript Question

how do i remove specific letters from alphabet string using regex

I have the alphabet as an uppercase string.

How do I remove the letters B G R P? I am using JavaScript.

I have tried:

replace(^/B/G/R/P/g, "")
replace(^[B,G,R,P]/g, "")

Answer

in php, would be somthing like this -

$string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$remove = preg_replace('/[BGRP]/', '', $string); 
// new string 
echo $remove;
Comments