Does a dot have to be escaped in a character class (square brackets) of a regular expression?

RegexStandardsStandards ComplianceSquare Bracket

Regex Problem Overview


A dot . in a regular expression matches any single character. In order for regex to match a dot, the dot has to be escaped: \.

It has been pointed out to me that inside square brackets [] a dot does not have to be escaped. For example, the expression: [.]{3} would match ... string.

Doesn't it, really? And if so, is it true for all regex standards?

Regex Solutions


Solution 1 - Regex

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

This website is a brilliant reference and has lots of info on the nuances of different regex flavours. http://www.regular-expressions.info/refcharclass.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDariuszView Question on Stackoverflow
Solution 1 - Regexlilactiger89View Answer on Stackoverflow