Multilingual Regular Expression Syntax (Pattern)

Regexp

About

Regular expression are Expressions that defines a pattern (ie structure) in text.

This is therefore a language that permits to define structure of a text.

They are a mathematically-defined concept, invented by Stephen Kleene in 1956. The original version defined expressions using:

The Glob language behave a lot like a regular expression but is not. The difference is mostly in the signification of the star and is use a lot in Shell in order to match file name. See Glob - Globbing (Wildcard expression).

Example

Simple Date Parsing

The below expression describes a date:

\d{4}-\d{2}-\d{2}

where:

It permits to parse ISO 86021 string date such as

2022-07-28

Log Parsing

Java regular expression used to parse log message at Twitter circa 2010

^(\\w+\\s+\\d+\\s+\\d+:\\d+:\\d+)\\s+
([^@]+?)@(\\s+)\\s+(\\S+):\\s+(\\S+)\\s+(\\S+)
\\s+((?:\\S+?,\\s+)*(?:\\S+?))\\s+(\\S+)\\s+(\\S+)
\\s+\\[([^\\]]+)\\]\\s+\"(\\w+)\\s+([^\"\\\\]*
(?:\\\\.[^\"\\\\]*)*)\\s+(\\S+)\"\\s+(\\S+)\\s+
(\\S+)\\s+\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)
\"\\s+\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"\\s*
(\\d*-[\\d-]*)?\\s*(\\d+)?\\s*(\\d*\\.[\\d\\.]*)?
(\\s+[-\\w]+)?.*$

where:

Usage

Regular expressions are used in many systems.

  • File Search. E.g., UNIX a.*b. known as glob
  • Data Structure Definition. Example:
    • DTD’s describe XML tags with a RE format like person (name, addr, child*).
  • Text extraction
  • Text matching

Syntax

/regularExpression/modifier

where:

See meta to get an overview of the most important regexp (symbols|token) that have a meaning in the context of regular expression.

Regular language and Automata

Regular expressions are implemented with context-free grammars and are the building block of regular language.

Stephen Kleene was the fellow who invented regular expressions and showed that they describe the same languages that finite automata describe. Most regexp-packages transform a regular expression into an automaton based on nondeterministic automata (NFA). The automaton does then the parse work.

Regular expression can be matched against text using a Definite Finite Automaton (DFA). DFA's have the important property of running on arbitrary text of length n in O(n) time and using O(1) space. Presented with a regular expression and a candidate text, a DFA decides whether the text matches the expression.

Engine / Grammar

The syntax can differ from one implementation to an other but then tend to follow the same principal.

The most known implementation is PCRE that is followed by most of the language

Visualisation

Regular expression are visualized via rail road diagram.

Cheatsheet

1) Regexp

2) 3) 4) 5)

Play: Crossword

https://regexcrossword.com/





Discover More
Card Puncher Data Processing
Automata - Automaton Library / State Machine

This page lists state machine libraries. All regular expression library implements an automaton. We list a couple of example. : Finite-state automaton for regular...
Card Puncher Data Processing
Code - Grammar / Syntax (Lexical)

This section regroups the entity of a computer language from a lexical point of view. It's the same as Parts of the speech for a natural language. Grammars are useful models when designing software...
Notepad Eol
Examples on how to replace a text in Notepad++ with regular expression

A step by step tutorial and snippets on how to replace a portion of text in notepad++ with regular expression
Model Funny
Function - Scalar

Scalar functions return a single value (as opposed to an array). Mathematics definition: Any function whose domain is a vector space and whose value is its scalar field. Is the result of a scalar function...
Regexp
Glob - Globbing (Wildcard expression)

Glob isNOT a regular language but is wildly used to define a set of filenames with wildcard characters. For instance, Bash provide globbing on filenames. The syntax is different by implementation and...
Scale Counter Graph
How to get Started With FluentBit

FluentBit from Calyptia is a log collector (ie observability pipeline tool) (written in C, that works on Linux and Windows). It's the Fluentd successor with smaller memory footprint When you need...
Postgres Elephant
How to get the schema of the function actually executing ?

With postgres, it's possible to get execution information by obtaining the execution stack . In the below function, we: retrieve the stack as a string extract the first function name via the...
Cookie Devtool
How to manage Cookies in the Browser via Javascript?

This article is HTTP cookies management in the client side (browser) via javascript. Cookie are one way to store data in the browser. document.cookie is a property of the browser document that returns...
How to use Regular expression (Regexp) in Javascript?

This page is regular expression in Javascript code unitssingle-character pattern (.) The pattern enclosed between slashes. Loaded compilation (only when the script is loaded) Runtime compilation...
Bash Liste Des Attaques Ovh
How to use Regular expression (regex) in Bash?

This article shous you how to use regular expression in Bash This example shows you how you can capture a Group to extract text. Example where we will extract a part of a file name When the...



Share this page:
Follow us:
Task Runner