Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the methods of the RegExp object

Shulou Source: shulou.com Published: 2022-06-02 15:33:27 10月04日 Update

This article mainly introduces "what are the methods of RegExp objects". In the daily operation, I believe that many people have doubts about the methods of RegExp objects. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions of "what are the methods of RegExp objects?" Next, please follow the editor to study!

Exec: retrieves a match represented by a regular character, returns the value found, and determines its location.

Eg:

Varstr= "abcdefg"

Varreg=/cd/

Varbol=reg.exec (str); / / return cd for success and null for failure

Test: retrieves the value specified in the string and returns true or false.

Eg:

Varbol=reg.test (str); / / return true for success and false for failure

Methods of the string object:

Match: find one or more regular representation matches

Search: retrieving values that match regular expressions

Replace: replaces a string that matches a regular expression

Split: separates a string into string numbers; / / the result is an array

Properties of the RegExp object:

Whether the global:RegExp object has the flag gbank / global query. If not, the operation ends after the first match.

Whether the ignorCase:RegExp object has the flag ibank / ignore case

Whether the multiline:RegExp object has the flag m _ bank / multi-line query

What are the common symbols of regular expressions

/. /: represents the beginning and end of a pattern

^: match the beginning of the string

$: the end of the matching string

S: any white space character

S: any non-white space character

D: matches a numeric character, level [^ 0-9]

D: any character other than a number is equivalent to [^ 0-9]

W: matches a number, underscore, or alphabetic character, equivalent to [A-Za-z0-9]

W: any non-word character, equivalent to [^ a-zA-Z0-9]

.: any character except a newline character

{n}: match the previous item n times

{n,}: match the previous term n times or multiple times

{nrecoery m}: match the previous item at least n times, but not more than m times

*: match the previous item 0 or more times, equivalent to {0,}

+: match the previous item one or more times, which is equivalent to {1,}

?: match the previous item 0 or 1 times, which is equivalent to {0reco1}

| |: indicates or; eg: [0-9] | [amurz] |

(): for grouping

Eg:

It's all letters:

Varreg=/ ^ [a-zA-Z] + $/; has at least one letter

Four letters:

Varreg=/ ^ [a-zA-Z] {4} $/; add'^'to avoid matching things like "3dedf".

11-digit qq number, the first digit cannot be 0:

/ ^ [1-9] {1} d {10} $/

18-digit ID number:

/ ^ d {17} (d {1} | [a-zA-Z} {1}) $/

Mailbox:

/ ^ w {2,} @ w {2,} (. [a-zA-Z] {2Magne 4}) {1pm 2} $/; so that you can match xx@yy.com.cn

At this point, the study of "what are the methods of RegExp objects" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Characters objects methods strings equivalence regular letters numbers learning flags expressions retrieval success properties more white space help query utility next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Huawei MariaDB Linux Redmi