Regular Expression Tester


Press Enter to see the result or Click on Button



Regex Explained

   A regular expression is a special text string to describe a search pattern. After the pattern is defined according to certain rules, it is applied to any text. Matches are checked after the process is finished. It may not be easy to find the desired pattern when Regexp works very well. Because of this, there are certain rules for patterning.

Pattern Rules

   The phrase regular expressions, and consequently, regexes, is often used to mean the specific, standard textual syntax for representing patterns for matching text. Each character in a regular expression (that is, each character in the string describing its pattern) is either a metacharacter, having a special meaning, or a regular character that has a literal meaning. We told them that there are certain rules for creating patterns. Lets review them in the following subheadings.

   ▪ Modifiers

The Modifiers simply specify the search level. In Javascript language it is taken as the 2nd parameter next to pattern.

i>> Perform case-insensitive matching

g>> Bring all matches

m>> Perform multiline matching

   ▪ Character classes & Brackets

[abc] >> a, b, or c (simple class)

[^abc] >> Any character except a, b, or c (negation)

[a-zA-Z] >> all letters small and large (but does not contain turkish characters)

[0-9] >> Between 0 and 9 matches

(a|b) >> Find any of the alternatives specified

   ▪ Metacharacters

. Finds any character

\w Find a word character

\W Find a non-word character

\d Find a digit

\D Find a non-digit character

\s Find a whitespace character

\S Find a non-whitespace character

   ▪ Quantifiers

* >> Match zero or more times

+ >> Match one or more times

? >> Match zero or one times

{n} >> Match exactly n times

{n,m} >> Match from n to m times

Regular Expression in Linux Terminal (GREP)

   The grep command is used to search text. It searches the given file for lines containing a match to the given strings or words. It is one of the most useful commands on Linux and Unix-like system. Let us see how to use grep on a Linux or Unix like system.

Basic using

grep "regexp" "file location"

"grep ‘brkuguz@gmail.com’ /home/burak/backup/log.txt"

The command above lists all the lines with "brkuguz@gmail.com". Text files do not have to have a .txt extension.

Advantages

-Portable

-One knowledge set spans multiple OS, languages and utilities

-Universally known in the UNIX world

-Much better than complex conditions

-One line of Regex can replace 100 lines of procedural code

-Easy to create by trial and error

-Less error prone than code