regex to match character in specific position

You say you're looking for C, F or E but looking for A in your example, so please include in the brackets any other letters you want to match, but what you're looking for is:

/^.{8}[CFE]/

It should be {8} rather than {9} because the way you had it, it'll match the first 9 characters and then match your letter in position 10.


This way can also solve the problem

/^.{8}A|^.{8}F|^.{8}E/;

you have to use 8 instead of 9 if you want to match the character on the 9th position


Use a character class:

/^.{9}[CFE]/
  • [CFE] matches one of C, F or E

Or use the | meta-character (alternation):

/^.{9}(?:C|F|E)/ 

Tags:

Regex