Powerful Regular Expression

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

What is Regular Expression?

1. Basic Rule of Patterns

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

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

^HELLO     // => HELLO Regular expression HELLOHELLO$     // => HELLO Regular expression HELLO
[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
.{5}        // => Hello Regular expression
[ELs]{1,3} // => HELLO Regular expressssion HELLO
[Ll}{2,} // => HELLO Regular expression HELLO

3. Quantifier Patterns * + ?

A*B        // => BC ABC AABC
A+B // => BC ABC AABC
A?B // => BC ABC AABC
.\* // => -@- *** @@ *** -@-
@+. // => -@- *** @@ *** -@-
-?@@?-
// => -@- *** -@@- *-@@@-
@A*@ // => -@- *** @@ *** -@-
-@+- // => -@- *** -- *** -@-
[-@]* // => -@- *** @@ *** -@-
[^ ]+ // => -@- *** @@ *** -@-
L.*        // => HELLO Regular expressssion HELLO
L.*? // => HELLO Regular expressssion HELLO
L.+ // => HELLO Regular expressssion HELLO
L.+? // => HELLO Regular expressssion HELLO
L.? // => HELLO Regular expressssion HELLO
[Ll].?? // => HELLO Regular expressssion HELLO

4. Sub Patterns ( | ?= ?! )

(on|ues|ednes)   // => Monday Tuesday Wednesday
..(n|es|dnes)day // => Monday Tuesday Wednesday

5. Built-in Regular Expression Patterns

\b.     // => HELLO Regular expressssion
\B. // => HELLO Regular expressssion
.\b // => HELLO Regular expressssion
.\B // => HELLO Regular expressssion
\A..     // => HELLO Regular expressssion
\Z.. // => HELLO Regular expressssion

6. Assertion Patterns

\w+(?=O)   // => HELLO Regular expressssion
\w+ // => HELLO Regular expressssion
\w+(?=\w) // => HELLO Regular expressssion
AAA(?!X)   // => AAAX---AAA

Software Engineer Student

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store