Powerful Regular Expression

Regular expressions are extremely useful and work with many programming languages.

Esther Kim
5 min readMay 31, 2020

--

What is Regular Expression?

Regular Expression (regex or regexp for short) is one of the methods for processing strings and makes it very easy to process the special text string for describing a search pattern or replacing characters in specific conditions. Let’s dive in a little deeper.

1. Basic Rule of Patterns

Regular expressions are case sensitive. Each character inside the search pattern is significant including whitespace characters (space, tab, newline).
If the literal value of a special character is required, it must be escaped with a /(backslash) and a regular expression . (dot) which is any character (wild card). If the dot is more than one, then it represents a specific number of characters.

.....      // => Hello Regular expression

2. Special Characters ^ $ [ ] and Quantifier Pattern { }

Some characters have special meanings. ^ (caret) matches the beginning of the line, and the $ (dollar sign) matches the end of the line.

^HELLO     // => HELLO Regular expression HELLOHELLO$     // => HELLO Regular expression HELLO

Inside the[] (square brackets), a list of characters can be provided. The expression matches if any of these characters is found. The order of characters is insignificant. A range of characters can be specified with [-] (hyphen/dash) and several ranges can be given in one expression. If a character class starts with ^ , then specified characters will not be selected.

[EsR]       // => HELLO Regular expression HELLO
[eE]. // => HELLO Regular expression HELLO
[e-s] // => HELLO Regular expression HELLO
[a-eA-E4-6] // => HELLO Regular expression HELLO 123456
[^ELest4-6] // => HELLO Regular expression HELLO 123456
[^1-3]. // => HELLO Regular expression HELLO 123456

--

--

Esther Kim

Software Engineer Student