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

In web regular expression. +? With. *? What's the difference?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the difference between. +? and. * in web regular expressions". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what's the difference between. +? and. *? in web regular expressions"!

. Matches any single character except "\ r\ n". To match any character including "\ r\ n", use a pattern like "[\ s\ S]".

? Match the previous subexpression 0 to 1 times * match the previous subexpression any number of times + match the previous subexpression one or more times > = 1)? Match the previous subexpression 0 to 1 times

If you add a question mark, it means lazy mode.

. +? Means to match one or more of any character

. *? Indicates that 0 or more characters match any character

In specific use. +? It may be easier to use, depending on your personal preference.

Now that you have written it, let's complete the regular knowledge by the way.

"\ b": does not consume any characters to match only one position. It is often used to match word boundaries. If I want to match the individual word "is" from the string "This is Regex", the rule is written as "\ bis\ b"\ b will not match the characters on both sides of the is, but it will recognize whether the two sides of the is are the word boundaries "\ d": match numbers, "\ w": match letters, numbers. Underline. "\ s": match spaces. ": match any character except the newline character (\ r\ n). This is an enhanced version of"\ w "."\ w "cannot match whites. if you add a string to a space with"\ w ", it is limited to use". " How to match the character "a2345 B C D__TTz" regular: ". +"[abc]": character group matching ability to match characters containing elements in parentheses (. >\ w >\ d)

Antonym:

The writing is very simple and can be changed to uppercase, which is easy to understand.

"\ W" matches any character that is not alphanumeric or underlined "S" matches any character that is not a blank character "\ D" matches any non-numeric character "\ B" matches a position that is not the beginning or end of a word "[^ abc]" matches any character "{n}" except abc repeats n times

For example, matching the an of a string from "aaaaaaaa" and repeating the regular 3 times: "a {3}" results in getting 3 a characters "aaa"

Repeat "{n ~ m}" n to m times

For example, regular "a {3pr 4}" repeatedly matches a for 3 or 4 times, so the matching characters can be three "aaa" or four "aaaa" regularities.

Repeat "{n,}" n or more times

What differs from {nrecom} is that there is no upper limit on the number of matches, but at least n times, such as regular "a {3,}" a, must be repeated at least 3 times.

"?" Repeat 0 or 1 times, but repeat as little as possible

For example, the regular "a. Aaacb" will only get the last three characters "acb".

"{nMagne m}?" Repeat n to m times, but repeat as little as possible

For example, the "aaaaaa" regular "a {0jue m}" is empty because it is at least 0 times.

"{n,}?" Repeat more than n times, but repeat as little as possible

For example, "aaaaa" regular "a {1,}" is at least once, so the result is "a" n + match n at least once (> = 1) n? Match n 0 times or once (with or without) n * match n at will (* can represent any letter)? = n matches any string immediately followed by the specified string n?! n matches any string that is not immediately followed by the specified string n.

= = > they are equivalent to each other

Now that you have a better understanding of "what is the difference between. +? and. *?" in web regular expressions, you might as well do some practical work. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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