Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

\ {\} in regular expressions-- the number of times matching patterns occur

Shulou Source: shulou.com Published: 2022-06-03 05:51:24 11月23日 Update

Regular expression:

The number of times matching characters appear

Use * to match all the matching results once, but if you only need to set the number of times, you should use\ {}. There are three forms of this pattern.

Pattern\ {n\} matching pattern occurs n times

Pattern\ {n,\} matching patterns occur at least n times

Pattern\ {NMagne m\} matching pattern occurs n to m times, and nMagne m is an arbitrary integer between 0 and 255respectively.

Example:

A\ {2\} B matching value is AAB

A\ {4\} B matching value is AAAAB or AAAAAAB, but cannot be AAAB

A\ {3pm 5\} matching value is AAAB,AAAAB,AAAAAB

Note: it is not difficult for regular expressions to use a single metacharacter, especially if multiple metacharacter sets are mixed.

Grep'^ H. [Amurz Zjinaqizi] s\ {2pr 4\} c$'./test

Tags: Pattern number regular expression metacharacter three forms between single multiple character integer time result don't mix Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Microsoft Huawei MariaDB macOS