The Dot (Regex)

The dot (.) is one of the most common metacharacters.

What are the metacharacters:

In regular expressions, there are characters with special meaning called metacharacters.
They do not result in a match for the character itself, but instead, change the rules for the match.
These are common metacharacters present in almost all implementations:
\ (backslash)
^ (caret)
$ (dollar sign)
. (dot)
| (vertical bar, the pipe symbol)
? (question mark)
* (asterisk)
+ (plus sign)
( ) (parentheses)
[ ] (square brackets)
{ } (curly braces)

The dot matches any single character (except line breaks).

Let’s say we want to find all the words that start with the word “code” but may end differently.
For example:
“My original code was saved in the file code1.js and the updated version is in codeFinal.js but I later changed code1.js to code1.old.js

The regex /code./ (note the dot at the end of “code”) will match all the words that contain “code“:

RegEx: /code./
String: “My original code was saved in the file code1.js and the updated version is in codeFinal.js but later I changed the code1.js to code1.old.js”

Note that the dot notation is selecting both, characters and digits.