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

How to use regular expressions in Category 11

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces you how to use regular expressions in Category 11, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

A regular expression is a text pattern. Regular expression is a powerful, convenient and efficient text processing tool. The regular expression itself, coupled with a general pattern representation (general pattern notation) like a pocket programming language, gives users the ability to describe and analyze text. With the additional support provided by the specific tools above, regular expressions can add, delete, detach, overlay, insert, and trim various types of text and data.

A complete regular expression consists of two types of characters: special characters (special characters) called "metacharacters" (meta characters), others as "literal", or plain text characters (normal text characters, such as letters, numbers, Chinese characters, underscores). The metacharacters of regular expressions provide more powerful description capabilities.

Like text editors, most high-level programming languages support regular expressions, such as Perl, Java, Python, and Cpicard Cellular expressions, all of which have their own regular expression packages.

A regular expression is only a string and has no length limit. "subexpression" refers to part of the entire regular expression, usually an expression in parentheses, or a multi-selected branch divided by "|".

By default, letters in expressions are case-sensitive.

Commonly used metacharacters:

1. ".": matches any single character except "\ n". To match any character including "\ n", use a pattern such as "[\ s\ S]".

2. "^": matches the starting position of the input string and does not match any characters. To match the "^" character itself, use "\ ^"

3. "$": matches the position at the end of the input string, but does not match any characters. To match the "$" character itself, use "\ $"

4. "*": match the previous character or subexpression zero or more times. "*" is equivalent to "{0,}", such as "\ ^ * b" can match "b", "^ b", "^ ^ b", …

5. "+": matches the preceding character or subexpression one or more times, which is equivalent to "{1,}". For example, "axib" can match "ab", "aab", "aaab", …

6. "?": zero or once matches the previous character or subexpression, which is equivalent to "{0men1}", such as "a [CD]?" Can match "a", "ac", "ad"; when this character follows any other qualifier "*", "+", "?", "{n}", "{n,}", "{n ·m}", the matching pattern is "non-greedy". The "non-greedy" pattern matches the shortest possible string found, while the default "greedy" pattern matches the searched string as long as possible. For example, in the string "oooo", "oops?" Matches only a single "o", while "o +" matches all "o"

7. "|": perform logical "or" (Or) operations on two matching conditions, such as regular expressions "(him | her)" match "itbelongs to him" and "itbelongs to her", but not "itbelongs to them."

8. "\": marks the next character as a special character, text, backreference, or octal escape character, such as "n" matches the character "n", "\ n" matches the newline character, the sequence "\" matches "\", "(" match "(" match ").

10. "\ W": matches any character that is not a letter, number, or underscore

11. "\ s": matches any blank character, including spaces, tabs, page feeds, etc., which is equivalent to "[\ f\ n\ r\ t\ v]"

12. "\ S": matches any character that is not a blank character, which is equivalent to "[^\ f\ n\ r\ t\ v]"

13. "\ d": matches a number, any number, any one of 09, equivalent to "[0-9]"

14. "\ D": matches any non-numeric character, which is equivalent to "[^ 0-9]"

15. "\ b": matches a word boundary, that is, the position between a word and a space, that is, the position between a word and a space, and does not match any characters, for example, "er\ b" matches "er" in "never", but does not match "er" in "verb".

16. "\ B": non-word boundary matching, "er\ B" matches "er" in "verb", but not "er" in "never"

17. "\ f": matches a feed character, which is equivalent to "\ x0c" and "\ cL"

18. "\ n": matches a newline character, which is equivalent to "\ x0a" and "\ cJ"

19. "\ r": matches a carriage return, which is equivalent to "\ x0d" and "\ cM"

20. "\ t": matches a tab, which is equivalent to "\ x09" and "\ cI"

21. "\ v": matches a vertical tab, equivalent to "\ x0b" and "\ cK"

twenty-two。 "\ cx": matches the control character indicated by "x", for example,\ cM matches Control-M or carriage return. The value of "x" must be between "Amurz" or "Amurz". If not, it is assumed that c is the "c" character itself.

23. "{n}": "n" is a non-negative integer that matches exactly n times. For example, "o {2}" does not match "o" in "Bob", but matches two "o" in "food".

24. "{n,}": "n" is a non-negative integer and matches at least n times. For example, "o {2,}" does not match "o" in "Bob", but matches all "o" in "foooood". "o {1,}" is equivalent to "o +" and "o {0,}" is equivalent to "o *".

25. "{n ·m}": "n" and "m" are non-negative integers, where n

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

Internet Technology

Wechat

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

12
Report