Regular expressions for string processing, form verification, and other occasions, practical and efficient. This article collects some common expressions:
$str = Preg_replace ("/( ) (. *?) (<\ a= ">)/", ' \1\2\3 ', $str);
It uses three sub modes (one in each parenthesis), the first is the link start tag, the second is the link text, and the third is
Then \1, \2, and \3 in the second argument means that these three parts, what to replace it is not easy?
Get the PHP function for all the linked addresses in the page
The following function, written in PHP, can get all the link addresses in any string $string ($string can be read directly from an HTML page file), and the result is returned in an array. The function automatically excludes e-mail addresses, And there are no duplicate elements in the returned array.
function Getalllink ($string)
{
$string = Str_replace ("\ R", "", $string);
$string = Str_replace ("\ n", "", $string);
$regex [url] = "((http|https|ftp|telnet|news): \/\/)? ([A-z0-9_\-\/\.] +\. [][a-z0-9:;&#@=_~%\?\/\.\,\+\-]+) ";
$regex [email] = ([a-z0-9_\-]+) @ ([a-z0-9_\-]+\.[ a-z0-9\-\._\-]+) ";
Remove the text between labels
$string = Eregi_replace (">[^<>]+<", "><", $string);
Remove JavaScript code
$string = Eregi_replace ("" , "", $string);
Get rid of non-HTML tags
$string = Eregi_replace ("<[^a][^<>]*>", "", $string);
get rid of email links
$string = Eregi_replace ("<a" ([]+) href= ([\ "]*) mailto: ($regex [email]) ([\" ']*] [^>]*> "," ", $string);
Replace the page link you want
$string = Eregi_replace ("<a" ([]+) href= ([\ "']* ') ($regex [url]) ([\ ']*] [^>]*>", "\\3\t", $string);
$output [0] = Strtok ($string, "T");
while (($temp = Strtok ("\ T"))
{
if ($temp &&!in_array ($temp, $output))
$output [+ + $i] = $temp;
}
return $output;
}
Here's a sample written in PHP syntax
Verify that the string contains only numbers and English, string length and between 4~16 characters
<?php
$str = ' a1234 '
if (Preg_match ("^[a-za-z0-9]{4,16}$", $str)) {
echo "Validation succeeded";} else {
echo "Validation lost?? quot;;}? >
Simple identification of the size of Taiwan's identity card
<?php
$str = ' a1234 '
if (Preg_match ("^: \ D{15}|\D{18}) $ ", $str)) {
echo "Validation succeeded";
} else {
echo "Validation lost?? quot;;}
?>
The following code implements the code block in the text, as you can see in the cloud-dwelling community network.
function Codedisp ($code) {
Global $discuzcodes;
$discuzcodes [' Pcodecount ']++;
$code = Htmlspecialchars (str_replace (' \ "', '" '), Preg_replace ("/^[\n\r]*" (. +?) [\n\r]*$/is "," \\1 ", $code)));
$discuzcodes [' codehtml '] [$discuzcodes [' pcodecount ']] = "
[Copy this Code]
The code is as follows:
". FHTML2 ($code)."
";
$discuzcodes [' Codecount ']++;
Return "[\tdiscuz_code_$discuzcodes[pcodecount]\t]";
}
$message = Preg_replace ("/\s*\[code\]" (. +?) \[\/code\]\s*/ies "," Codedisp (' \\1 ') ", $message);
$message = Preg_replace ("/\s*\[html\]" (. +?) \[\/html\]\s*/ies "," Htmldisp (' \\1 ') ", $message);
Matching regular expressions for Chinese characters: [\U4E00-\U9FA5]
Commentary: Matching Chinese is really a headache, with this expression will be easy to do
Match Double-byte characters (including Chinese characters): [^\x00-\xff]
Commentary: can be used to compute the length of a string (a double-byte character length meter 2,ascii 1 characters)
A regular expression that matches a blank row: \n\s*\r
Commentary: can be used to delete blank lines
Regular expression:< matching HTML tags (\s*?) [^>]*>.*?| <.*?>
Commentary: The online version is too bad, the above can only match the part of the complex nested tags still powerless
A regular expression that matches the end-end whitespace character: ^\s*|\s*$
Commentary: A useful expression that can be used to delete white-space characters (including spaces, tabs, page breaks, and so on) at the end of a line at the beginning
Regular expression matching an email address: \w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *
Commentary: Form validation is useful
Regular expressions that match URL URLs: [a-za-z]+://[^\s]*
Commentary: Online circulation of the version of the function is very limited, which can meet the basic requirements
Match account number is legal (beginning of letter, allow 5-16 bytes, allow alphanumeric underline): ^[a-za-z][a-za-z0-9_]{4,15}$
Commentary: Form validation is useful
Match domestic phone number: \d{3}-\d{8}|\d{4}-\d{7}
Commentary: Match form such as 0511-4405222 or 021-87888822
Matching Tencent QQ Number: [1-9][0-9]{4,}
Commentary: Tencent QQ number starting from 10000
Match China ZIP Code: [1-9]\d{5} (?! \d)
Commentary: China postal code is 6 digits
Matching ID: \d{15}|\d{18}
Commentary: China's ID card is 15-or 18-digit
Matching IP address: \d+\.\d+\.\d+\.\d+
Commentary: Useful when extracting IP addresses
Match a specific number:
^[1-9]\d*$//Matching positive integer
^-[1-9]\d*$//matching negative integers
^-? [1-9]\d*$//matching integer
^[1-9]\d*|0$//matching nonnegative integer (positive integer + 0)
^-[1-9]\d*|0$//matching non positive integer (negative integer + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$//matching positive floating-point numbers
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*) $//matching negative floating-point number
^-? ([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0) $//matching floating-point number
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$//matching nonnegative floating-point number (positive floating-point number + 0)
^ (-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)) |0?\.0+|0$//matching non-positive floating-point numbers (negative floating-point number + 0)
Commentary: useful when dealing with large amounts of data, pay attention to corrections when applied
Match a specific string:
^[a-za-z]+$//Match a string of 26 English letters
^[a-z]+$//Match a string of 26 uppercase letters
^[a-z]+$//Match string consisting of 26 lowercase letters
^[a-za-z0-9]+$//Match a string of numbers and 26 English letters
^\w+$//Match A string of numbers, 26 English letters, or underscores
Here are some special characters:
Special characters in regular expressions: (Learning Reference books-<< proficient in regular expressions, > >)
Character
Meaning: For a character, it is usually indicated by literal meaning that the character followed by a special character is not interpreted.
For example:/b/matches the character ' B ', which becomes a special character by adding a backslash before B, i.e./b/, which means
Match the dividing line of a word.
Or:
For a few characters, usually the description is special, indicating that the character immediately followed is not special, but should be interpreted literally.
For example: * is a special character that matches any character (including 0 characters), for example:/a*/means matching 0 or more aces.
To match the literal *, precede a with a backslash; For example:/a*/matches a ' * '.
Character ^
Meaning: The character that matches must be at the front.
For example:/^a/does not match the ' a ' in ' an A ', but matches ' an A. ' The "A" in the front.
Character $
Meaning: Similar to ^, matches the last character.
For example:/t$/does not match ' t ' in ' eater ', but matches ' t ' in ' eat '.
Characters
Meaning: matches the characters of the preceding 0 or n times.
For example:/bo*/matches ' B ' in ' boooo ' or ' a bird warbled ' in ' a ghost booooed ', but does not match ' a goat g
runted any character in the ".
Character +
Meaning: Matches the character preceded by the + number 1 or n times. Equivalent to {1,}.
For example:/a+/matches ' a ' and ' Caaaaaaandy ' in ' Candy '. All ' a ' in.
Character?
Meaning: match the preceding character 0 or 1 times.
For example:/e?le?/matches ' el ' and ' angle ' in ' Angel '. ' Le ' in the.
Character.
Meaning: (decimal point) matches all individual characters except for line breaks.
For example:/.n/matches ' an ' and ' on ' in the ' nay ', an apple are on the tree, but does not match ' nay '.
Character (x)
Meaning: Matches ' X ' and records the matching value.
For example:/(foo)/Match and record "Foo bar." In the ' foo '. The matching substring can be in the result array of the element [1], ..., [n] Return
Back, or the attributes of the RegExp object are $, ..., the $ return.
Character X|y
Meaning: Match ' x ' or ' Y '.
For example:/green|red/matches ' green ' and ' Red apple ' in ' green apple '. In the ' Red '.
Character {n}
Meaning: Here The n is a positive integer. Matches the preceding n characters.
For example:/a{2}/does not match "a" in "Candy," but matches "Caandy," all ' a ' and "Caaandy." Two in front of
' A '.
Character {n,}
Meaning: Here The n is a positive integer. Matches at least n preceding characters.
For example:/a{2,} does not match ' a ' in ' Candy ', but matches all ' a ' and ' Caaaaaaandy ' in ' Caandy '. All ' a ' in the
Character {n,m}
Meaning: Here the N and M are all positive integers. Matches at least n up to m preceding characters.
For example:/a{1,3}/does not match any of the characters in "Cndy", but matches the first two in "a", "Caandy," in "Candy,"
"A" and "Caaaaaaandy" in front of the three ' a ', note: even if "caaaaaaandy" there are many ' a ', but only match the previous three
A ' a ' or ' AAA '.
character [XYZ]
Meaning: A list of characters that matches any one of the characters listed. You can indicate a range of characters through hyphens.
For example: [ABCD] is the same as [a-c]. They match the ' C ' in ' B ' and ' ache ' in ' brisket '.
character [^XYZ]
Meaning: A character complement, that is, it matches everything except the characters listed. You can use hyphens--point out a
The range of characters.
For example: [^ABC] and [^a-c] are equivalent, they first match the ' R ' and ' chop ' in ' brisket '. In the ' H '.
Character
Meaning: Match a space (do not confuse with B)
Character B
Meaning: Match the dividing line of a word, such as a space (not with confusion)
For example:/bnw/matches ' no ' in ' Noonday ',/wyb/matches ' possibly yesterday. ' In the ' ly '.
Character B
Meaning: A non-dividing line that matches a word
For example:/wbn/matches ' on ' in ' Noonday ',/ybw/matches ' possibly yesterday. ' In the ' ye '.
Character CX
Meaning: Here The X is a control character. Matches the control character of a string.
For example:/cm/matches the control-m in a string.
Character D
Meaning: Matches a number, equivalent to [0-9].
For example:/d/or/[0-9]/matches "B2 is the" suite number. In the Ƈ '.
Character D
Meaning: Matches any non-numeric, equivalent to [^0-9].
For example:/d/or/[^0-9]/matches "B2 is the" suite number. In the ' B '.
Character F
Meaning: matches a form character
Character N
Meaning: matches a newline character
Character R
Meaning: matches a carriage return character
Character S
Meaning: Matches a single white spaces, including spaces, tab,form feeds, line breaks, equivalent to [FNRTV].
For example:/sw*/matches "foo bar." ' Bar ' in the.
Character S
Meaning: matches a single character except white spaces, equivalent to [^ FNRTV].
For example:/s/w* matches "foo bar." In the ' foo '.
Character T
Meaning: Match a tab
Character V
Meaning: Match a head tab
Character W
Meaning: Matches all numbers and letters and underscores, equivalent to [a-za-z0-9_].
For example:/w/matches "A" in "Apple," "$5.28," "Ƌ" and "3D." In the Ɖ '.
Character W
Meaning: Matches other characters except numbers, letters, and underscores, equivalent to [^a-za-z0-9_].
For example:/w/or/[^ $A-za-z0-9_]/match "50%." In the '% '.
Character N
Meaning: Here The n is a positive integer. Matches the value of N of the last substring of a regular expression (counting the left parenthesis).
For example:/apple (,) sorange1/match "Apple, orange, cherry, peach." In the ' Apple, Orange ', below
There is a more complete example.
Note: If the number in the left parenthesis is smaller than the number specified in N, then N takes a row of octal escape as a description.
Character Ooctal and Xhex
Meaning: The ooctal here is a octal escape value, and Xhex is a hexadecimal escape value that allows ASCII code to be embedded in a regular expression.
Common mode
Delimiters, usually using "/" as a delimiter to start and end, or "#" can be used.
When do you use "#"? Typically there are a lot of "/" characters in your string, because the characters need to be escaped, such as URIs.
The code that uses the "/" delimiter is as follows.
<?php
$regex = '/^http://([w.] +)/([w]+)/([w]+). html$/i '
$str = ' http://www.youku.com/show_page/id_ABCDEFG.html '
$matches = Array ();
if (Preg_match ($regex, $str, $matches)) {
Var_dump ($matches);
}
echo "n";
$matches[0] In Preg_match will contain a string that matches the entire pattern.
The code that uses the "#" delimiter is as follows. This time the "/" is not escaped!
$regex = ' #^http://([w.] +)/([w]+)/([w]+). html$ #i '
$str = ' http://www.youku.com/show_page/id_ABCDEFG.html '
$matches = Array ();
if (Preg_match ($regex, $str, $matches)) {
Var_dump ($matches);
}
echo "n";
Modifier: Used to change the behavior of a regular expression.
We see ('/^http://[w.] +)/([w]+)/([w]+). html/i ') The last "I" is a modifier, which indicates that the case is ignored, and one of the most common uses of "X" is to ignore spaces.
Contribution code:
$regex = '/hello/'
$str = ' Hello word '
$matches = Array ();
if (Preg_match ($regex, $str, $matches)) {
Echo ' No i:valid successful! ', "n";
}
if (Preg_match ($regex. ' I ', $str, $matches)) {
Echo ' YES i:valid successful! ', "n";
}
Word Value field: [W] the part that is enlarged with square brackets is the character field.
Qualifiers: Symbols that are followed by [w]{3,5} or [w]*, or [W] (w]+) represent qualifiers. The specific meaning is introduced.
{3,5} represents 3 to 5 characters. {3,} more than 3 characters, {, 5} up to 5, {3} three characters.
* Represents 0 to many
+ represents 1 to many.
Off-character symbol
^:
> put in the Word value field (such as: [^w]) to express the negation (not included)--"Reverse selection"
> precede the expression to indicate the start of the current character. (/^n/i, which means beginning with n).
Note that we often call the "jump off character". Used to escape some special symbols, such as ".", "/"
Bounds: Regular expressions are generally as follows:
/love/
The part of the "/" delimiter is the pattern that will be matched in the target object.
Metacharacters: Refers to those special characters that have special meaning in regular expressions that can be used to specify the mode in which the leading character (that is, the character at the front of the metacharacters) appears in the target object.
The more commonly used meta characters include: "+", "*", and "?".
The "+" metacharacters specify that their leading characters must appear consecutively or repeatedly in the target object
The "*" Meta character stipulates that its leading characters must appear 0 or more times in the target object,
“?” The metacharacters specify that their leading characters must appear 0 or one consecutive times in the target object.
Next, let's look at the specific application of regular expression meta characters.
/fo+/
Because the preceding regular expression contains a "+" meta character (preceded by "O" as a leading character), it indicates that a string of one or more letters O can be matched with the "fool", "fo", and so on in the target object after the letter F.
In addition to metacharacters, users can specify exactly how often a pattern will appear in a matching object. For example
/jim{2,6}/
The regular expression above stipulates that the character M can appear consecutively 2-6 times in a matching object, so the regular expression above can match a string such as Jimmy or Jimmmmmy.
The use of several other important metacharacters.
S: Used to match a single spaces, including tab keys and line breaks;
S: Used to match all characters except a single spaces;
D: Used to match numbers from 0 to 9;
W: Used to match letters, numbers or underscore characters;
W: used to match all characters that do not match w;
. : Used to match all characters except for line breaks.
(Note: We can think of S and S and W and W as inverse)
Below, let's take a look at how to use the above metacharacters in regular expressions.
/s+/
The preceding regular expression can be used to match one or more whitespace characters in the target object.
In addition to the meta characters we have described above, there is another unique special character in the regular expression, that is, the locator.
Locator character: Used to specify where the match pattern appears in the target object.
The more commonly used locator characters include: "^", "$", "B" and "B".
The "^" locator stipulates that the match pattern must be present at the beginning of the target string
The "$" locator stipulates that the matching pattern must be present at the end of the target object
The B-Locator stipulates that the matching pattern must now be one of the two boundaries at the beginning or end of the target string
The "B" locator stipulates that the matching object must be within two boundaries at the beginning and end of the target string, that is, the matching object can neither be the beginning of the target string nor the end of the destination string. Similarly, we
You can also think of "^" and "$" and "B" and "B" as two sets of locators that are mutually inverse operations. For example:
/^hell/
Because the above regular expression contains the "^" Locator, you can match a string that starts with "hell", "Hello", or "Hellhound" in the target object.
/ar$/
Because the preceding regular expression contains a "$" locator, you can match a string that ends with "car", "bar", or "AR" in the target object.
/bbom/
Because the preceding regular expression pattern starts with a "B" locator, it can match a string that starts with "bomb" or "BOM" in the target object.
/manb/
Because the above regular expression pattern ends with a "B" locator, you can match a string that ends with "human", "Woman", or "man" in the target object.
In order to make it easier for users to set a matching pattern, regular expressions allow the user to specify a range in the matching pattern and not be limited to specific characters. For example:
/[a-z]/
The regular expression above will match any uppercase letter from A to Z range.
/[a-z]/
The regular expression above will match any lowercase letter from a to Z range.
/[0-9]/
The regular expression above will match any number in the range from 0 to 9.
/([a-z][a-z][0-9]) +/
The regular expression above will match any string of letters and numbers, such as "aB0". The point to note here is that you can use "()" to group strings together in regular expressions.
"()" symbol: The contained content must appear in the target object at the same time. Therefore, these regular expressions will not match strings such as "ABC", because the last character in "ABC" is a letter rather than a number.
If we want to implement a "or" operation in a regular expression that is similar in programming logic, you can use the pipe character: "|" in any number of different patterns. For example:
/to|too|2/
The regular expression above will match the "to", "too", or "2" in the target object.
Negative character: "[^]". Unlike the locator "^" described in the previous article, the negative character "[^]" stipulates that the string specified in the pattern cannot exist in the target object. For example:
/[^a-c]/
The above string will match any character except A,b, and C in the target object. Generally, when "^" appears inside "[]", it is regarded as a negation operator, and when "^" is outside "[]" or there is no "[]", it should be treated as a locator character.
Finally, when users need to add metacharacters to the pattern of regular expressions and find their matching objects, you can use the
Escape character: "". For example:
/th*/
The regular expression above will match the "th*" in the target object, not the "the".
Introduction to practical experience
Still have to say ^ and $ they are used to match the start and end of a string, respectively, with the following examples:
"^the": The beginning must have "the" string;
"Of despair$": The end must have a string of "of despair";
So
"^abc$": a string that requires the beginning of ABC and the end of ABC, which is actually only an ABC match;
"Notice": matches a string containing notice;
You can see if you don't use the two characters we mentioned (the last example), which means that the pattern (regular expression) can appear anywhere in the string being tested, you don't lock him on either side.
Then, say ' * ' + ' and '? '
They are used to indicate the number of times a character can appear or the order they represent:
"Zero or more" equals {0,}
"One or more" equals {1,}
"Zero or one." Equivalent to {0,1}
Here are some examples:
"ab*": and Ab{0,} synonymous, matching with a start, followed by 0 or n B of the string ("a", "AB", "abbb", etc.);
"ab+": and Ab{1,} synonymous with the same as above, but at least a B exists ("AB" "abbb", etc.);
"Ab?" : and ab{0,1} synonymous, can not or only a B;
"a?b+$": a string that matches the end of one or 0 a plus more than one B.
Main points: ' * ' + ' and '? ' just the character in front of it.
You can also limit the number of characters appearing in curly braces, such as:
"Ab{2}": Require a must be followed by two B (one also can not be less) ("ABB");
"Ab{2,}": Require a must have two or more than two B (such as "ABB" "abbbb", etc.);
' ab{3,5} ': Requires that a 2-5 B ("abbb", "abbbb", or "abbbbb") be followed by a.
Now we put a few characters into parentheses, such as:
"A (BC) *": Match a followed by 0 or a "BC";
"A (BC) {1,5}": one to 5 "BC";
There is also a character ' | ', which is equivalent to an OR operation:
"Hi|hello": matches a string containing "hi" or "hello";
"(B|CD) EF": Matches a string containing "bef" or "cdef";
"(a|b) *c": matches a string containing such multiple (including 0) A or B, followed by a C;
A point ('. ') can represent all single characters, excluding ""
What if you want to match all the individual characters, including ""?
Use ' [.] ' This pattern.
"A.[0-9]": A plus one character plus a number of 0 to 9;
^. {3}$: Three any character end.
The content enclosed in brackets matches only one single character
"[AB]": Match a single A or B (as with "a│b");
[a-d]: a single character that matches ' a ' to ' d ' (same as ' a│b│c│d ' and ' [ABCD] ' effect);
Generally we use [a-za-z] to specify characters for a single case in English:
"^[a-za-z]": matches a string that begins with the uppercase and lowercase letters;
"[0-9]%": matches a string containing a shape such as x percent;
", [a-za-z0-9]$": A string that matches a comma with a number or letter ending;
You can also put you don't want to get the character column in brackets, you just need to use ' ^ ' in the parentheses as the opening "%[^a-za-z]%" match contains two percent signs inside a non-alphanumeric string.
Important: ^ When used at the beginning of brackets, the characters in parentheses are excluded.
For PHP to be able to explain, you have to add "around these character surfaces" and to escape some characters.
Don't forget that the characters inside the brackets are exceptions to this rule road-inside the brackets, all the special characters, including ("), will lose their special properties" [*+?{}.] Matches a string containing these characters:
And, as REGX's Handbook tells us: "If the list contains '," It's best to use it as the first character in the table (probably following ' ^ '). If it contains '-', it's best to put it on the front or the last side.
, or or the second end point of a range [a-d-0-9] in the middle of '-' will be valid.
Looking at the above example, you should understand {n,m}. Note that both N and m cannot be negative integers, and n is always less than M. In this way, you can match at least N times and match up to M times. such as "p{1,5}" will match
The first five p in "PVPPPPPP"
Let's talk about the beginning.
b It says he's used to match a word boundary, which is ... such as ' VEB ', can match the love of VE but does not match very have ve
b Just as opposed to B above.
Other uses of regular expressions
Extract string
Ereg () and eregi () has an attribute that allows the user to extract part of the string through a regular expression (you can read the manual). For example, we want to extract the filename from Path/url, and the following generation
Code is what you need:
Ereg ("([^\/]*) $", $PATHORURL, $regs);
echo $regs [1];
High-level substitution
Ereg_replace () and Eregi_replace () are also useful if we want to replace all the interval minus signs with commas:
Ereg_replace ("[t]+", ",", Trim ($STR));
The following are the referenced contents:
Preg_match () and Preg_match_all ()
Preg_quote ()
Preg_split ()
Preg_grep ()
Preg_replace ()
The specific use of the function, we can find through the PHP manual, the following share some of the regular expressions accumulated:
Match Action Property
The following are the referenced contents:
$str = '
$match = '
Preg_match_all ('/s+action= ') (?!) http:) (. *?) " S/', $str, $match);
Print_r ($match);
Using callback functions in regular
The following are the referenced contents:
/**
* Replace some string by callback function
*
*/
function Callback_replace () {
$url = ' http://esfang.house.sina.com.cn '
$str = '
$str = Preg_replace ('/<=saction= ') (?!) http:) (. *?) (? = "s)/e ', ' Search ($url, \1) ', $str);
Echo $str;
}
function Search ($url, $match) {
Return $url. '/' . $match;
}
A regular match with assertions
$match = '
$str = ' xxxxxx.com.cn bold font
Paragraph text
'
Preg_match_all ('/(?<=< (W{1}) >). * (? =)/', $STR, $match);
echo "matches the contents of an HTML tag without attributes:";
Print_r ($match);
Replace the address in the HTML source code
The following are the referenced contents:
$form _html = Preg_replace ('/(? <=saction= "|ssrc=" |shref= ") (?! Http:|javascript) (. *?) (? = "s)/e ', ' Add_url ($url, ' \1 ') ', $form _html);
Metacharacters
In the example above, these symbols, ^, d, and $, represent specific matching meanings, which we call Meta characters, and the common metacharacters are as follows:
Metacharacters description
. Matches any character that is unexpected except for line breaks
W matches letters or numbers or underscores
s matches any blank character.
D Matching numbers
b matches the start or end of a word
^ Start of Match string
$ end of Match string
[x] matches x characters, such as A, B, and C characters in a matching string
The inverse of W, that is, a character that matches any non-letter, number, underscore, or kanji.
The inverse of s s, that is, a character that matches any of the non-white characters
The inverse of D D, that is, any character that matches any non-numeric
B is the opposite of the word, which is not the beginning or the end
[^x] matches any character except x that is unexpected, such as [^ABC] matches any character other than the ABC letters