Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Regular expression Grammar & Collection

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Regular expression

A regular expression is a text pattern that includes ordinary characters (for example, letters between an and z) and special characters (called metacharacters). The pattern describes one or more strings to match when searching for text.

Regular expression sample expression matching

/ ^\ sstories /

Matches a blank line.

/\ d {2} -\ d {5} /

Verify the ID number consisting of two digits, a hyphen, and five digits.

/] *)? > [\ s\ S] * /

Matches the HTML tag.

The following table contains a complete list of metacharacters and their behavior in the context of regular expressions:

Character description

\

Marks the next character as a special character, text, backreference, or octal escape character. For example, "n" matches the character "n". "\ n" matches the newline character. Sequence "\" match "," ("match" ().

^

Matches the position where the input string begins. If the Multiline property of the RegExp object is set, ^ also matches the position after "\ n" or "\ r".

$

Matches the position at the end of the input string. If the Multiline property of the RegExp object is set, $also matches the position before "\ n" or "\ r".

*

Matches the previous character or subexpression zero or more times. For example, zo* matches "z" and "zoo". * equivalent to {0,}.

+

Matches the previous character or subexpression one or more times. For example, "zo+" matches "zo" and "zoo" but not "z". + is equivalent to {1,}.

?

Matches the previous character or subexpression zero or once. For example, "do (es)?" Matches the do in "do" or "does". ? It is equivalent to {0jue 1}.

{n}

N is a non-negative integer. It happens to match n times. For example, "o {2}" does not match "o" in "Bob", but matches two "o" in "food".

{n,}

N is a non-negative integer. Match at least n times. For example, "o {2,}" does not match "o" in "Bob", but matches all o in "foooood". "o {1,}" is equivalent to "o +". "o {0,}" is equivalent to "o *".

{n,m}

M and n are non-negative integers, where n

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report