Programming | network
1. Explanation of regular expression <a\s+href\s*=\s* ""? ([^ ">]+)" "?> (. +) </a> The meaning of each part of the representative.
"Answer" this regular expression is used to match a string that is similar to the Sohu news in the source file, and each part means:
\s+ one or more whitespace characters
HREF is followed by the exact text in the HTML anchor point
\s* 0 or more white space characters
= followed by the exact text in the HTML anchor point
\s* 0 or more white space characters
""? 0 or no quotes (escaped)
(The starting point of the group that defines the substring (anchor URL).
[^ ' ">]+ one or more occurrences of any character, except for the characters in parentheses.
Defines the end of the first group of substrings
""? 0 or no quotes (escaped)
> followed by the exact text in the HTML anchor point
(. +) A group that matches any character (anchored point text).
End the exact text of an HTML anchor point
2. The following is a regular expression that checks whether the input string is a valid e-mail message:
^ ([\w-]+\.) *? [\w-]+@[\w-]+\. ([\w-]+\.) *? [\w]+$
Try to explain the meaning of each part.
Troubleshooting
[\w-]+
One or more arbitrary characters (A-Z, A-Z, 0-9, and underscores) or dashes. On both sides of the @ character, make sure the address form is name@domainname.
\.
An escape point number. (without a backslash, a point number matches any single character except the newline character.) To ensure that there is at least one point number in the domain name.
*?
For the previous expression, not greedy (non-greedy, or minimal) to find 0 or more matches.
([\w-]+\.) *?
Combination of the above three expressions:
For an expression that contains one or more arbitrary characters (A-Z, A-Z, 0-9, and underscores) or dashes, followed by only a point number, it is not greedy to find 0 or more occurrences.
3. Write out regular expressions that meet the following requirements:
1 requires 4-8 letters in English.
2) cannot contain letters, at least 1 characters.
3) at least 3 digits.
4) at least 3 characters.
5) At least 3 English letters.
6) any character.
7) 3 letters or numbers, such as 123,R3A.
8) 3 points.
9 @ There are at least 1 characters before @, @ after at least 3 characters.
10) You must enter an opening parenthesis.
Troubleshooting
1) [a-za-z]{4,8}
2) [^a-za-z]{1,}
3) [0-9]{3,}
4) {3,}
5) [A-za-z]{3,}
6). {0,}
7) [A-za-z0-9]{3}
8) \. {3}
9). {1,}@. {3,}
10) \ (