Multilingual Regular Expression Syntax (Pattern)

> Procedural Languages > Multilingual Regular Expression Syntax (Pattern)

1 - About

This section talks about the Regular Expression Syntax.

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.

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 (Wildcard).

2 - Syntax

A regular expression is composed of:

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

Advertising

3 - Grammar

4 - Example

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:

Advertising

5 - Documentation / Reference

lang/regexp/regexp.txt · Last modified: 2019/06/13 14:41 by gerardnico