-1

How would one write a regex expression in python re, where the pattern is : 3 english letters followed by a comma

Example:

string_var = "AAA, BBB, CCC"  # follows the pattern 
string_var = "AAA, BBBB, CCC, DDD" # does not follow the pattern
thshea
  • 617
  • 3
  • 14
Ryuu
  • 15
  • 4

2 Answers2

-1

If you want to only check if a string matches, use ^[A-Za-z]{3}, [A-Za-z]{3}, [A-Za-z]{3}$ (https://regexr.com/5i22s). This will be true for "AAA, BBB, CCC", but is not useful for finding matches like in "test asf, cat, dog".

^        Start of string
[A-Za-z] Alphabet characters
{3}      3 alphabet characters
,        A comma followed by a space
...
$        End of string
thshea
  • 617
  • 3
  • 14
-1

Try this

^([a-zA-Z]{3},\s){2}[a-zA-Z]{3}$

or use this with re.I flag

^([a-z]{3},\s){2}[a-z]{3}$
Hirusha Fernando
  • 458
  • 2
  • 16