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

What are the methods of the RegExp object

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

Share

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

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!

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

Development

Wechat

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

12
Report