What is Regular Expression ?
theoretical computer science and formal language theory, a regular expression (abbreviated regex or regexp) is a sequence ofcharacters that forms a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. "find and replace"-like operations. The concept arose in the 1950s, when the American mathematician Stephen Kleene formalized the description of a regular language, and came into common use with the Unix text processing utilities ed, an editor, and grep (global regular expression print), a filter.
Each character in a regular expression is either understood to be a metacharacter with its special meaning, or a regular character with its literal meaning. Together, they can be used to identify textual material of a given pattern, or process a number of instances of it that can vary from a precise equality to a very general similarity of the pattern. The pattern sequence itself is an expression that is a statement in a language designed specifically to represent prescribed targets in the most concise and flexible way to direct the automation of text processing of general text files, specific textual forms, or of random input strings.
A very simple use of a regular expression would be to locate the same word spelled two different ways in a text editor, for exampleseriali[sz]e. A wildcard match can also achieve this, but wildcard matches differ from regular expressions in that wildcards are limited to what they can pattern (having fewer metacharacters and a simple language-base), whereas regular expressions are not. A usual context of wildcard characters is in globbingsimilar names in a list of files, whereas regular expressions are usually employed in applications that pattern-match text strings in general. For example, the simple regexp^[ \t]+|[ \t]+$ matches excess whitespace at the beginning and end of a line. An advanced regexp used to match any numeral is ^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$. See Examples for more examples.
A regular expression processor processes a regular expression statement expressed in terms of a grammar in a given formal language, and with that examines the target text string, parsing it to identify substrings that are members of its language, the regular expressions.
Regular expressions are so useful in computing that the various systems to specify regular expressions have evolved to provide both abasic and extended standard for the grammar and syntax; modern regular expressions heavily augment the standard. Regular expression processors are found in several search engines, search and replace dialogs of several word processors and text editors, and in the command lines of text processing utilities, such as sed and AWK.
Many programming languages provide regular expression capabilities, some built-in, for example Perl, Ruby, AWK, and Tcl, and others via a standard library, for example .NET languages, Java, Python and C++ (since C++11). Most other languages offer regular expressions via a library.
Regular Expression Syntax in Flex:
Flex's syntax is same as Lex lexical analysis tool. You can get knowledge about the regular expression syntax of Lex from here: http://dinosaur.compilertools.net/lex/
No comments:
Post a Comment