I am attempting to create a function that can match one occurrence of a certain character and two occurrences of another character simultaneously. For instance, in the string "_Hell_o"
, I want to match the first underscore (_) and in the string "++Hello"
, I need to match both plus signs (+). Ideally, the function would look like this:
function check(str) {
console.log(str.replace(/[_+{2}]/, ''));
}
check("++Hello");
check("_Hello");
check("+Hello");
The expected outputs are supposed to be:
>>> Hello
>>> Hello
>>> +Hello
However, this particular function is not functioning correctly.