Application of Regular Expressions
1. // is short for M //./http: // is not easy to read. You can write m {http: //} or M % http: // %
2. The forward slash is not a metacharacter. If it is not a separator, you do not need to use a backslash before it.
3./Fred/I, indicating that the case sensitivity is ignored. It can match Fred, etc.
4 .. line breaks cannot be matched, but after S is added, all characters, such as/f. */s, can be matched to all strings starting with F
5. X allows spaces or tabs in the mode to facilitate reading and understanding. That is to say, spaces and tabs in the mode will be ignored, such /-? /D + /.? /D */x
6. The above three optional modifiers can be used at the same time without limiting the order, six, Xis, ISX, xsi, ixs, sxi
7. There are other modifiers... =. =
8./^ Fred/, indicating matching at the beginning of the string,/Fred $/indicating matching at the end of the string the first 4 characters before the... string, and the last 4 characters of the string
9./^/S * $/common usage. It can match empty rows. If no pin is needed, it can match any row.
10. anchor,/B, is used for words. for example, // bfred/B/can match the word Fred, but cannot match Frederick, Alfred, man Fred Mann. similar to "full match"
11./B. You can use only one. Well, you should understand the effect.
12./B, indicating that the domain is not anchored. // bfred/B/, cannot match Fred.
13. = ~, This mode matches $ _ by default, but the string on the left is matched.
14. You can use parameter interpolation or even @ agrv to obtain the mode.
15.$ _ = "Hello there, neighbor"; <br/> If (/S +), (/S + )/) {<br/> Print "words were $1 $2 $3 "; <br/>}< br/> # words were hello there neighbor will be output. <br/> # A bracket corresponds to a $ x
16. The values of these matching variables (stored in memory) remain unchanged until the next mode is successfully matched.
17. that is to say, a pattern that does not match will not change the corresponding value in the memory, but a pattern that matches will overwrite the memory. this clearly tells you not to use these variables unless you know that they match correctly. Otherwise, you may get the result of the previous pattern match. playing memory is not good...
18. Therefore, the pattern matching pair is used for condition judgment or while. After matching, use it as soon as possible.
19. $ &, $ 'and $'... Perl are symbolic languages... =
20. The matching strings will be automatically stored in $ &
21. $ & for the entire matching part (what is in the pattern and what is it), unlike $ X, $ X is only the value of the () block corresponding to the Pattern
22. $ 'is $ & no front part, $' is $ & no later part
23. If you use any of the three auto-matching variables, the running of Regular Expressions in other places will slow down no matter where the program is located.
24. So try not to use it...
25. other quantifiers,/a {5, 15}/, indicates matching 5 to 15... in fact, only five or more matches can be matched, but if the output is at most 15. if expression a appears three times, the number of times is too small to match. If expression a appears five times, it is matched. If expression a appears 10 times, it is still matched. if it appears 20 times, it will still match, and the first 15 will match.
26. Priority:
(1). brackets are at the top of the priority table.) When grouping and referencing memory values, use any part inside the. bracket to be closer than that outside the brackets;
(2). The second level is a quantizer. Here there are stars (*), plus signs (+), question marks (?), And the quantifiers represented by curly brackets, such as {5, 15}, {3,}, {5}. They are usually combined with the previous element.
(3 ). the third level is the anchor and sequence anchor includes (^) indicating the start of the string, ($) indicating the end, (/B) bounded word, (/B) non-word identifier. A sequence (followed by an element) is actually an operation, although it does not use metacharacters. the meaning of this passage is that the letters in a word are more closely integrated, just as they are anchored to the letter.
(4 ). the lowest priority is the vertical line (|), indicating or. because of its lowest priority, the pattern is usually divided into several parts. it is at the bottom of the priority because we want to be closer together with letters or (|) Like |/Fred | Barney. if or (|) has a higher priority than the sequence, the above pattern means matching FRE,
Followed by D or B, followed by arney. Therefore, or (|) has the lowest priority, and the letter sequence has a higher priority.
27. One Pattern Matching Test Program#! /Usr/bin/perl <br/> while (<>) {<br/> chomp; <br/> If (/your_partten_goes_here /) {<br/> Print "matched: | $ '<$ &> $' |/N "; # Special variables <br/>}else {<br/> Print "no match: |$ _ |/N"; <br/>}