Regular expression without characters

I have this regex

([AZ], )* 

which must match test, (with a space after the decimal point)

How to change the expression of a regular expression so that if there are any characters after the space, it does not match. For example, if I had:

 test, test 

I want to do something like

 ([AZ], ~[AZ])* 

Greetings

+8
regex
source share
3 answers

Use the following regular expression:

 ^[A-Za-z]*, $ 

Explanation:

  • ^ matches the beginning of a line.
  • [A-Za-z]* matches 0 or more letters (case insensitive) - replace * with + so that 1 or more letters are required.
  • matches a comma followed by a space.
  • $ matches the end of the line, so if there is something after the comma and space, the result will fail.

As already mentioned, you should indicate which language you use when asking a Regex question, as there are many different varieties that have their own characteristics.

+16
source share
 ^([AZ]+, )?$ 

The difference between mine and the donut is that it will match and will not contain an empty string, mine will correspond to an empty string and will not be executed for,. (and that it is more case insensitive than mine. With my help, you need to add case insensitivity to your regular expression function variants, but this is similar to your example)

+1
source share

I'm not sure which regular expression engine / language you use, but often there is something like a group of negative characters [^az] , which means "everything except the character".

0
source share

All Articles