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 carry on the basic Analysis of regular expression

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

Share

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

How to carry out the basic analysis of regular expressions, in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

[^\ d] non-numeric character =\ D [^\ w] non-word character =\ W [^\ s] non-blank character =\ S

A regular expression is a Mini Program that has its own simple programming language. The string is divided into two groups (match / mismatch) by pattern.

1. A simple pattern (/ /) that matches a simple direct quantity string.

$_ = "yabba dabba doo"; if (/ abba/) {print "It matched!\ n"; # return match as true}

two。 Metacharacters that have a special meaning in regular expressions.

. A wildcard that matches any character, except\ n.

\ add a backslash before the metacharacter to create an escape so that the latter metacharacter has no special function.

() Mode grouping

3. Quantifier

* match the previous entry zero or more times. ". *" means to match any character zero or more times.

+ match the previous entry more than once.

? Match the previous entry zero or once.

4. Mode grouping

() grouping strings

For example: / fred+/ can match fredddddd strings, which is not common every day.

/ (fred) + / matches the fredfredfred string.

5. Parentheses () can be used for backreferences, that is, to capture group behavior.

The reverse reference is written as\ 1\ 2. Or\ g {1}\ g {2}. The corresponding number represents the capture group in the corresponding order.

For example:

$_ = "abba"; if (/ (.)\ 1 /) {# (.)\ 1 indicates that two identical characters will be matched. Print "bb";}

A reverse reference does not have to be immediately after the corresponding capture group, or there can be multiple parentheses for multiple capture groups, each with its own reverse reference

For example:

$_ = "yabba dabba doo"; if (/ y (.) (.)\ 2\ 1 /) {print "abba";}

6. Choose a match "|", which means "or"

For example:

/ fred (|\ t) + barry/ # means to match a string in which spaces, tabs, or a mixture of both appear more than once between fred and barry.

7. A character set is a set of possible characters

[] it matches any single character listed in the character set, with a-concatenated range, such as [a-zA-Z]. -has a special meaning in the character set, but not outside the character set.

8. Abbreviation of character set

\ d strictly equal to character set [0-9]

\ s matches any blank character [\ f\ t\ b\ r]. Page feed\ f, horizontal tab\ t, line feed\ n, carriage return\ r, space character.

\ h match horizontal white space character

\ v match vertical white space character

\ w matches [a-zA-Z0-9], and can also match words.

9. Antisense abbreviation

[^\ d] non-numeric character =\ D

[^\ w] non-word characters =\ W

[^\ s] the answer to the question on how to perform the basic analysis of regular expressions is shared here. I hope the above content can be of some help to you, if you still have a lot of doubts to be solved. You can follow the industry information channel for more related knowledge.

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