Search⌘ K
AI Features

Literal Character

Explore how literal characters work in regular expressions to match exact sequences of text. Understand case sensitivity, the use of global and case-insensitive flags, and practice matching letters and numbers. This lesson helps you grasp fundamental regex matching and prepares you for more complex patterns.

Overview of Literal Characters

Let’s deep dive into literal pattern matching.

Property of Literal Character: Matches all the characters with the same properties in the same way.

To match texts as they are, we generally use literal characters.

An example to match alphabets

For example, to match all the words containing “cat”, the RegEx will be /cat/. Remember, by default, RegEx will only display the first result. To match all instances of /cat/, use the global flag (g). We can also create a RegEx consisting of a single character. Suppose you want to match each occurrence of the number “1”, then the RegEx will be /1/.

Suppose, you are provided with the text “cat, catastrophic, catalyst”. It will start by matching the character “c” from RegEx with the character “c” from the text, which will match. It will then move to the next character. It will match the character “a” and then the ...