Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the differences between (parentheses), [braces] and {curly braces} in regular expressions

Shulou Source: shulou.com Published: 2022-06-02 03:43:07 11月15日 Update

This article mainly introduces the regular expressions (parentheses), [braces], {curly braces} what are the differences, have a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

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

() is to extract the matching string. If there are several () in the expression, there are several matching strings.

(\ s*) A string that represents consecutive spaces.

[] is the range of characters that define a match. For example, [a-zA-Z0-9] means that the characters in the corresponding position should match English characters and numbers. [\ s*] indicates a space or a * sign.

{} is generally used to indicate the length of a match, for example,\ s {3} means to match three spaces, and\ s [1pr 3] means to match one to three spaces.

(0-9) match'0-9 'itself. [0-9] * matching numbers (note that there is a *, which can be empty) [0-9] + matching numbers (note that there is a + after it, which cannot be empty) {1-9} spelling error.

[0-9] {0jue 9} represents a numeric string of length from 0 to 9.

For example: filter content in PHP with numbers or spaces in it

Preg_replace ("/\ d {1,}\ s {0jue 1} /", "xxxxxxxx", $signaturecontent); Thank you for reading this article carefully. I hope the article "what are the differences between regular expressions (parentheses), [braces] and {curly braces}" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Characters numbers spaces parentheses expressions strings articles regular square brackets three length different value position interest content writing at the same time meaning more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux Apple Redmi macOS