Basic syntax of regular expressions (transfer)

xiaoxiao2021-03-04  58

Basic syntax of regular expression

Author: sxqyj

Let us first look at the two special symbols '^' and '$'. Their role is to point out the beginning and end of a string. The example is as follows: "^ the": indicates all strings starting with "THE" ("there", "THE CAT", etc.); "of despair $": indicates the string ending with "of despair"; "^ ABC $ ": Indicates that the start and end are string of" abc "- huh, only" ABC ";" NOTICE ": indicates any string containing" Notice ". The last example, if you don't use two special characters, you are in any part of the string to find the string - you don't position it on a top. Others have the three symbols of '*', ' ' and '' ', indicating that one or a sequence character is repeated. They represent "no or more", "once or more" and "no or once". Here are a few examples: "ab *": means a string having a A back followed by zero or several b. ("A", "ab", "abbb", ...); "ab ": indicates a string having a A followed by at least one B or more; "ab?": Indicates a string has a A back Follow zero or one B; "a? B $": indicates that there is zero or one A followed one or more b at the end of the string. You can also use the scope, enclose with braces to indicate the range of repetitions. "AB {2}": means a string has a A follow 2 B ("abb"); "AB {2,}": indicates a string having a A follow at least 2 b; "AB {3, 5} ": Represents a string having a A follows 3 to 5 B. Note that you must specify the lower limit of the range (such as "{0, 2}" instead of "{, 2}"). Also, you may notice, '*', ' ' and '' '' correspond to "{0,}", "{1,}" and "{0, 1}".

转载请注明原文地址:https://www.9cbs.com/read-31670.html

New Post(0)