Regular Expressions Working with Special Characters

Learning objective: By the end of this lesson, students will understand how to use special characters as text within regular expressions.

Escaping special characters

We’ve seen how certain characters such as /*+?.[]{}, have special meaning in regular expressions.

That being the case, how do we match these special characters as literal characters? For example, what if you wanted a pattern to match a number that includes a decimal point?

📚 Escaping characters can be necessary when using languages or technologies where certain characters are assigned special meaning, like in regex. Escaping a character strips the character of its special meaning, and makes it behave like any other character.

For example, this pattern: What\? would match the string What?.

🎓 You Do

Write the regular expression that would match a floating-point number with one more more digits on both sides of the decimal.