1. Common usage.
Char STR [512] = {0 };
Sscanf ("123456", "% s", STR );
Printf ("str = % s/n", STR );
2. Take a string of the specified length. In the following example, a string with a maximum length of 4 bytes is obtained.
Sscanf ("123456", "% 4 s", STR );
Printf ("str = % s/n", STR );
3. Obtain the string of the specified character. For example, in the following example, the string is obtained when a space is encountered.
Sscanf ("123456 abcdedf", "% [^]", STR );
Printf ("str = % s/n", STR );
4. Take a string that only contains the specified character set. For example, in the following example, take a string that only contains 1 to 9 letters and lowercase letters.
Sscanf ("123456 abcdedfbcdef", "% [1-9a-z]", STR );
Printf ("str = % s/n", STR );
5. Obtain the string of the specified character set. For example, in the following example, a string with uppercase letters is used.
Sscanf ("123456 abcdedfbcdef", "% [^A-Z]", STR );
Printf ("str = % s/n", STR );
---------------------------------
There are multiple regular expressions. The following table shows a complete list of metacharacters in PCRE and their rows in the context of positive Notation:
Character Description
/Mark the next character as a special character, or an original character, or a forward reference, or an octal delimiter. For example, "N" matches the character "N 」. "/N" matches a line character. The sequence "//" matches "/" and "/(" matches 「(」.
^ Matches the starting position of the substring. If the multiline embedding of Regexp is set, ^ matches the position after "/N" or "/R.
$ Matches the end position of the substring. If the multiline encoding of Regexp is set, $ also matches the position before "/N" or "/R.
* Match the preceding sub-table limit type zero or multiple times. For example, Zo * can match "Z" and "Zoo 」. * Wait until {0 ,}.
+ Match the preceding sub-table values once or multiple times. For example, "zo +" can match "zo" and "Zoo", but cannot match "Z 」. + Equal to {1 ,}.
? Match the preceding sub-table limit type zero or one time. For example, do (ES )?」 It can match "do" in "do" or "does 」.? Wait for {0, 1 }.
{N} n is a non-integer. Matches a specified number of times. For example, "O {2}" cannot match "O" in "Bob", but it can match two "O" in "food.
{N,} n is a non-integer. Match at least N times. For example, "O {2,}" cannot match "O" in "Bob", but it can match all o in "foooood. "O {1,}" and so on are stored in "O + 」. "O {0,}" is equal to "O *」.
{N, m} m and n are non-integer values, where n <= m. Match at least N times and at most m times. For example, "O {1, 3}" matches the first three o in "fooooood. "O {0, 1}" and so on are stored in "O ?」. Please note that there cannot be spaces between the two numbers.
? When the character delimiter follows any other delimiter (*, + ,?, After {n}, {n ,},{ n, m}), the matching mode is non-linear. In non-linear regression mode, the primary key may be less matched to the searched token string, while in the hidden primary key mode, the primary key may be more matched to the searched token string. For example, for the metastring "oooo" and "O ++ ?」 A single "O" will be matched, while "O +" will match all "O 」.
. Match any single character except "/N. To match any character that contains "/N", use a mode like "[./N.
(Pattern) matches pattern and returns this match. The obtained match can be obtained from the generated matches set. The submatches set is used in VBScript, and $0… is used in JScript... $9 adequacy. To match the delimiter, use "/(" or 「/)」.
(? : Pattern) matches pattern but does not match the result. That is to say, this is a non-sequential match, which is used after the row is saved for supply. This is useful when you use the "or" character (|) to combine various parts of a single mode. For example, "industr (? : Y | ies.
(? = Pattern) forward lookup. Match the source string at the beginning of any substring that matches pattern. This is a non-Fetch match, that is, the match does not need to be used after the fetch is used. For example (? = 95 | 98 | nt | 2000) "can match" Windows "in" Windows2000 ", but cannot match" Windows "in" windows3.1 」. The keyword query does not consume characters, that is, after a match is generated, the next match is started immediately after the last match, instead of starting from the character that contains the marker query.
(?! Pattern) matches the source string to search for any source string that does not match pattern. This is a non-Fetch match, that is, the match does not need to be used after the fetch is used. For example, "windows (?! 95 | 98 | nt | 2000) "can match" Windows "in" windows3.1 ", but cannot match" Windows "in" Windows2000 」. The keyword query does not consume characters, that is, after a match is generated, the next match is started immediately after the last match, instead of starting from the character that contains the marker Query
X | y matches X or Y. For example, "z | food" can match "Z" or "food 」. "(Z | f) Ood" matches "zood" or "food 」.
[Xyz] Character Set combination. Match any character contained. For example, "[ABC]" can match "A" in "plain 」.
[^ XYZ] delimiter value character set combination. Match any character not included. For example, "[^ ABC]" can match "P" in "plain 」.
[A-Z] character. Matches any character in the specified delimiter. For example, "[A-Z]" can match any small character in "A" to "Z" character.
[^ A-Z] delimiter value character. Match any character that is not in the specified delimiter. For example, "[^ A-Z]" can match any character that is not in the range from "A" to "Z.
/B matches a single word field, that is, the location between a single word and a space. For example, "ER/B" can match "er" in "never", but cannot match "er" in "verb 」.
/B matches non-single words. "Er/B" can match "er" in "verb", but cannot match "er" in "never 」.
/CX matches the control characters specified by X. For example,/cm matches a control-M or carriage return character. The value of X must be either a A-Z or a-Z. Otherwise, convert C to the original "C" character.
/D matches a data element. Wait for [0-9].
/D matches a non-numeric element. Wait for [^ 0-9].
/F matches a token. Such as/x0c and/Cl.
/N matches a line character. Such as/x0a and/CJ.
/R matches a carriage return. Wait for/x0d and/cm.
/S matches any blank characters, including spaces, delimiter, and delimiter. And so on in [/f/n/R/T/V].
/S matches any non-blank characters. Wait for [^/f/n/R/T/V].
/T matches a forward table. Wait for/x09 and/CI.
/V matches a vertical delimiter table. Wait for/x0b and/ck.
/W matches any single word characters including the lower limit. Wait on [A-Za-z0-9 _].
/W matches any non-single-word characters. Wait until [^ A-Za-z0-9 _].
/XN matches n, where N is the hexadecimal scalar value. The hexadecimal notation must be a fixed length of two numbers. For example, "/x41" matches "」. "/X041" is equal to "/x04" and "1 」. ASCII character can be used in the regular expression of the positive table ..
/Num matches num, where num is a positive number. References to the matched signature. For example, "(.)/1" matches two identical characters.
/N indicates an octal scalar value or a forward reference. If there are at least n sub-tables obtained before/n, n is referenced to the backend. Otherwise, if n is an octal digit (0-7), n is an octal scalar value.
/Nm indicates an octal scalar value or a forward reference. If at least one sub-table has a forward child table before/nm, the NM is referenced to the backend. If there are at least N delimiters before/nm, n is a back-to-back reference of Text M. If both N and m are octal numerals (0-7), then/nm matches the octal Scalar Value nm.
/NML if n is an octal number (0-3) and M and l are both Octal numbers (0-7 ), then match the octal signature value NML.
/UN matches n, where n is a Unicode character represented by four hexadecimal characters. For example,/u00a9 matches the copyright ().