Estoy tratando de escribir una expresión regular similar a
^[a-zA-Z.{0,1},{0,1}'{0,1}]*Sin embargo, esto puede aceptar más de una coma, punto y apóstrofes.
Por ejemplo, se permite "String.,'" pero no se debe permitir "str.,..,,,'''".
Usar
^(?!.*([.,']).*\1)[a-zA-Z.,']*$Ver prueba de expresiones regulares .
EXPLICACIÓN
-------------------------------------------------------------------------------- ^ the beginning of the string -------------------------------------------------------------------------------- (?! look ahead to see if there is not: -------------------------------------------------------------------------------- .* any character except \n (0 or more times (matching the most amount possible)) -------------------------------------------------------------------------------- ( group and capture to \1: -------------------------------------------------------------------------------- [.,'] any character of: '.', ',', ''' -------------------------------------------------------------------------------- ) end of \1 -------------------------------------------------------------------------------- .* any character except \n (0 or more times (matching the most amount possible)) -------------------------------------------------------------------------------- \1 what was matched by capture \1 -------------------------------------------------------------------------------- ) end of look-ahead -------------------------------------------------------------------------------- [a-zA-Z.,']* any character of: 'a' to 'z', 'A' to 'Z', '.', ',', ''' (0 or more times (matching the most amount possible)) -------------------------------------------------------------------------------- $ before an optional \n, and the end of the string