Regular expressions-tutorial

Regular expression (Regular Expression) is a text pattern that includes ordinary characters (for example, letters between a to z) and special characters (called "metacharacters").

Regular expressions use a single string to describe and match a series of strings that match a syntactic rule.

Regular expressions are tedious, but it is powerful. The application after learning will let you not only increase efficiency, but also bring you a sense of absolute accomplishment. As long as you read this tutorial carefully and add some references when applying, mastering regular expressions is not a problem.

Many programming languages support string operations using regular expressions.


The following example finds the number from the string str:


Extract the content of the digital part from the string str (match once):

var str = "abc123def"; var patt1 = /[0-9]+/; document.write(str.match(patt1));

The text marked below is the matching expression obtained: