Regular Expression MANOJ K. https://www.drupal.org/u/manojapare @manojapare
What is regular expression? Usage of regular expression? Basics Agenda
What is regular expression? A sequence of characters that define a search pattern. The concept arose in the 1950s when the American mathematician Stephen Cole Kleene formalized the description of a regular language. The concept came into common use with Unix text-processing utilities.
Usage of regular expression? Regular expressions are used in Search engines Search and replace dialogs of word processors and text editors Text processing utilities such as sed and AWK and in lexical analysis. Many programming languages provide regex capabilities, built-in or via libraries.
Basics Character classes Anchors Escaped Characters Groups & Lookaround Quantifiers & Alternation
Character classes . any character except newline \w \d \s word, digit, whitespace \W \D \S not word, not digit, not whitespace [abc] any of a, b, or c [^abc] not a, b, or c [a-g] character between a & g
Anchors ^abc$ start / end of the string \b \B word boundary, not-word boundary
Groups & Lookaround (abc) capture group \1 backreference to group #1 (?:abc) non-capturing group (?=abc) positive lookahead (?!abc) negative lookahead
Quantifiers & Alternation a* a+ a? 0 or more, 1 or more, 0 or 1 a{5} a{2,} exactly five, two or more a{1,3} between one & three a+? A{2,}? match as few as possible ab|cd match ab or cd