Regular Expressions (parentheses), [brackets], {curly Braces} differences Summary _ Regular expressions

Source: Internet
Author: User

The () [] {} of the regular expression has different meanings.

() is to extract a matching string. Several () of the expressions have several corresponding matching strings.

(\s*) A string that represents a contiguous space.

[] is the range of characters that define the match. For example, [a-za-z0-9] represents the corresponding position of characters to match English characters and numbers. [\s*] denotes a space or * number.

{} is typically used to indicate the length of a match, such as \s{3} to match three spaces, \s[1,3] to match one to three spaces.

(0-9) match ' 0-9′ itself. [0-9]* Matching digits (note that there are *, can be empty) [0-9]+ matching digits (note that there are +, not nullable) {1-9} spelling errors.

[0-9] {0,9} represents a numeric string that is 0 to 9 in length.

For example: Filter content in PHP with numbers or spaces

Copy Code code as follows:

Preg_replace ("/\d{1,}\s{0,1}/", "xxxxxxxx", $signaturecontent);

PS: About regular, this site also provides 2 very simple and practical regular expression tool for everyone to refer to use:

JavaScript Regular expression online test tool:
Http://tools.jb51.net/regex/javascript

Regular expression online generation tool:
Http://tools.jb51.net/regex/create_reg

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.