Literal Character

Learn about the simplest matching in RegEx.

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 character “t”. The ...

Access this course and 1400+ top-rated courses and projects.