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
  • 318
  • 3
  • 13
  • 40

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
  • 761,203
  • 64
  • 569
  • 643
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,805
  • 8
  • 54
  • 86