October 2018
Beginner to intermediate
466 pages
12h 2m
English
If putting a period character in a pattern matches any arbitrary character, how do we match just a period in a string? One way might be to put the period inside square brackets to make a character class, but a more generic method is to use backslashes to escape it. Here's a regular expression to match two-digit decimal numbers between 0.00 and 0.99:
'0.05' matches pattern '0\.[0-9][0-9]' '005' does not match pattern '0\.[0-9][0-9]' '0,05' does not match pattern '0\.[0-9][0-9]'
For this pattern, the two characters \. match the single . character. If the period character is missing or is a different character, it will not match.
This backslash escape sequence is used for a variety of special characters in regular expressions. ...
Read now
Unlock full access