Home > front end >  ¿How would be a regex for only vowells and numbers?
¿How would be a regex for only vowells and numbers?

Time:05-15

Very simple direct question, I need a regex for pattern in a Input wich only accepts vowells and numbers => It must contain both

CodePudding user response:

If a string has both a vowel and a digit, either:

  • the digit is in front of the vowel (ie digit random stuff vowel)
  • The digit is behind the vowel (ie vowel random stuff digit)

Hence the following regex should work:

let regex = /[aeiouAEIOU].*[0-9]|[0-9].*[aeoiuAEIOU]/

Test cases:

Regex Test Cases

CodePudding user response:

Here is the regex, it's not the best but it works:

https://regexr.com/6llkt

If you want documentation about regex:

https://www.geeksforgeeks.org/write-regular-expressions/

  • Related