lundi 25 novembre 2019

Create a simple case-insensitive RegEx which is made up of ONLY vowels and prime numbers?

rules:

the entire string for the pattern must be 4 characters in size.

it can contain vowels (a,e,i,o,u) and the first 4 prime numbers ( 2,3,5 and 7).

make it so that if you enter a vowel in uppercase, it still works.

My solution/attempt:

/^(?i)[a|e|i|o|u|2|3|5|7]{4}$/

but I can't help but wonder if its the most compact way of doing it, there has to be a way to shorten this ? ranges perhaps ? or break this down into two seperate expressions which work in unison ?

Using the above rules and expression the following would be observed:

E5i3 = TRUE ( valid )

o7A3 = TRUE ( valid )

0eiA = FALSE ( invalid )

is there a better way to shorten the expression i'm using ?

Aucun commentaire:

Enregistrer un commentaire