regex remove 3 characters before and after /

looking for a simple regular expression for this,

This is the input:

This is a sample text

eiwen34EDJ/VUFercsFIR/GRSnrr

Output:

eiwen34 ercs nrr

I want to remove 3 characters before and after '/'. i.e. In terms of my example, EDJ/VUF and FIR/GRS should be removed.

I was searched for many questions in here but didn't find the solution for it, please help me.

2 answers

  • answered 2017-11-14 23:52 KevBot

    You can use:

    /[a-z]{3}\/[a-z]{3}/gi
    

    This checks for 3 characters before and after the slash and replaces with a space:

    var string = 'eiwen34EDJ/VUFercsFIR/GRSnrr';
    
    var newString = string.replace(/[a-z]{3}\/[a-z]{3}/gi, ' ');
    
    console.log(newString);

  • answered 2017-11-15 01:11 Allan

    You can also use the following regex replacement, where you don't need to put it in case insensitive.

    /[A-z]{3}\/[A-z]{3}/g