0

User input might look like:

  • * symbol with 1 character limit (no other symbols than *)

or

  • A-E, a-e letters with 1 character limit

Following data is valid examples: *; a; A; e; D

I don't understand why ^[A-Ea-e]{1}\*?$ doesn't work?

https://regex101.com/r/iG7wG6/1

demonoid
  • 198
  • 3
  • 12
  • 36

2 Answers2

2

You just need a character class:

^[A-Ea-e*]$

RegEx Demo

You regex is only allowing an optional * after A-E or a-e but never * alone.

anubhava
  • 713,503
  • 59
  • 514
  • 593
1

Try using regex groups:

^([A-Ea-e]|\*)$

You want to have two different alternatives:

  1. one of the A-E or a-e characters, OR
  2. the * character.
Krease
  • 15,296
  • 8
  • 50
  • 85