Regular Expressions - Tutorial
A regular expression (regex) is a text pattern consisting of ordinary characters (e.g., letters from a to z) and special characters known as "metacharacters."
Regular expressions use a single string to describe and match a series of strings that conform to a syntactic rule.
While regex can be cumbersome, it is powerful, and learning it will not only boost your efficiency but also give you a sense of accomplishment. By carefully reading this tutorial and referring to it when applying regex, mastering it is not a problem.
Many programming languages support string operations using regular expressions.
Example
The following example extracts numbers from the string str
:
Example
Extract the numeric part from the string str
(match once):
var str = "abc123def";
var patt1 = /[0-9]+/;
document.write(str.match(patt1));
The following marked text is the matched expression: 123
Testing Tool
Modifier:
[0-9]+
Matching Text:
abc123def
Content List
- Regular Expressions - Introduction
- Regular Expressions - Syntax
- Regular Expressions - Metacharacters
- Regular Expressions - Operator Precedence
- Regular Expressions - Matching Rules
- Regular Expressions - Examples
- Regular Expressions - Online Tools
- Regular Expressions - Visualization Tool