IHYPRESS PROGRAMMING
Tutorials and JavaScript programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
share
JavaScriptTutorials ❯ Regular Expressions
A regular expression (regex) is a sequence of characters that forms a search pattern. They are used for text searching, replacing, and validation. A regular expression pattern is placed between two forward slashes like this /pattern/i where pattern is the string pattern to be used in the search and i is a modifier flag (in this case i means case-insensitive).
Methods
In JavaScript, the three methods making common use of regular expressions are search(), match() and replace().
Alternatives
In a regular expression, alternatives are denoted with a vertical line character |. It matches any of the alternatives separated with |.
Modifiers (Flags)
Regular expression flags are optional parameters that can modify how a regex pattern is interpreted and applied.
Metacharacters
Metacharacters are characters with a special meaning. They can be used to match digts, words, spaces, and more.
Character Classes
Character classes are enclosed in square brackets []. It matches any character from the set within the brackets.
Boundaries
Some boundaries match operators:
Quantifiers
Quantifiers define the numbers of characters or expressions to match. Works with the pattern preceding them. Some examples with the letter 'a' as the pattern:
Escape Sequences
Some characters like ^, $, \, ., *, +, ?, (, ), [, ], {, }, | have special meanings in regular expressions and need to be escaped with a backslash (\) if you want to match them literally. For example /3\.1416/ matches the exact 3.1416 pattern but /3.1416/ matches 3 followed by any single character then 1416 so 3f1416 would be a match.
Hergestellt in Deutschland / Made in Germany
COPYRIGHT © 2015-2026 IHY PRESS Frankfurt am Main 60329 Deutschland