Can someone explain with need \ char before dot at pattern

Like

Username with 2-20 chars

^[a-zA-Z][a-zA-Z0-9-_\.]{1,20}$

- and _ chat is fine but with if not set \ before .? I try works both ways? Why use? \. or just .

Thanks!

In a character class (square brackets) any character except ^ , - , ] or \ is a literal.

Which is why it works both ways.

2 Likes