Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Regular Expressions - Tutorial

Regular Expressions - Tutorial

Regular Expression (abbreviated as Regex or RegExp) is a pattern used to match character combinations in strings.

Regular expressions are a tool used for pattern matching and searching text.

Regular expressions provide a flexible and powerful way to find, replace, validate, and extract text data.

Regular expressions can be applied in various programming languages and text processing tools, such as JavaScript, Python, Java, Perl, etc.

Getting started video:Regular Expressions Beginner Tutorial.


What can regular expressions do?


Example

The following example finds numbers in the string str:

Example

Extract the numeric portion from the string str (match once):

var

str

=

"

abc123def

"

;

var

patt1

= /

[

0

9

]

+/;

document

.

write

(

str

.

match

(

patt1

)

)

;

The text marked below is the expression that obtains the match:

123

Try it »

Testing Tool

Modifiers:

[0-9]+

Match text:

abc123def

Regular expression patterns

A regular expression pattern can include the following:

Table of contents

Other related tools