RegExp with only one letter

1

I wanted to make a RegExp that would look more or less like 0000-x , that would be available only the letter X and numbers from 0 to 9. I gave a search on the net, I was able to do with numbers only or to get all the letters .

Here's an example I made, just numbers: link

    
asked by anonymous 14.10.2014 / 17:53

1 answer

3

Just use one set:

[xX\d] para 0 a 9 OU x
[0-9xX] para 0 a 9 OU x
[xX] para SOMENTE x

Applying to your case:

v=v.replace(/^(\d{4})([0-9x])/g,"$1-$2");


When you use sets in RegExp , you are saying "any of these characters". Examples:

[a-zA-Z0-9] Qualquer letra minúscula ou maiúscula, ou os dígitos de 0 a 9
[abcdABCD]{2} Qualquer combinação de 2 caracteres como aB, DD, Da, db, etc
    
14.10.2014 / 17:56