⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perlrebackslash.1

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 1
📖 第 1 页 / 共 2 页
字号:
.PPOctal escapes potentially clash with backreferences. They both consistof a backslash followed by numbers. So Perl has to use heuristics todetermine whether it is a backreference or an octal escape. Perl usesthe following rules:.IP "1." 4If the backslash is followed by a single digit, it's a backreference..IP "2." 4If the first digit following the backslash is a 0, it's an octal escape..IP "3." 4If the number following the backslash is N (decimal), and Perl already hasseen N capture groups, Perl will consider this to be a backreference.Otherwise, it will consider it to be an octal escape. Note that if N > 999,Perl only takes the first three digits for the octal escape; the rest ismatched as is..Sp.Vb 6\& my $pat  = "(" x 999;\&    $pat .= "a";\&    $pat .= ")" x 999;\& /^($pat)\e1000$/;   #  Matches \*(Aqaa\*(Aq; there are 1000 capture groups.\& /^$pat\e1000$/;     #  Matches \*(Aqa@0\*(Aq; there are 999 capture groups\&                    #    and \e1000 is seen as \e100 (a \*(Aq@\*(Aq) and a \*(Aq0\*(Aq..Ve.PP\fIHexadecimal escapes\fR.IX Subsection "Hexadecimal escapes".PPHexadecimal escapes start with \f(CW\*(C`\ex\*(C'\fR and are then either followed bytwo digit hexadecimal number, or a hexadecimal number of arbitrary lengthsurrounded by curly braces. The hexadecimal number is the code point ofthe character you want to express..PPNote that a character that is expressed as a hexadecimal escape is consideredas a character without special meaning by the regex engine, and will match\&\*(L"as is\*(R"..PPMnemonic: he\fIx\fRadecimal..PPExamples.IX Subsection "Examples".PP.Vb 4\& $str = "Perl";\& $str =~ /\ex50/;    # Match, "\ex50" is "P".\& $str =~ /\ex50+/;   # Match, "\ex50" is "P", it is repeated at least once.\& $str =~ /P\ex2B/;   # No match, "\ex2B" is "+" and taken literally.\&\& /\ex{2603}\ex{2602}/ # Snowman with an umbrella.\&                    # The Unicode character 2603 is a snowman,\&                    # the Unicode character 2602 is an umbrella.\& /\ex{263B}/         # Black smiling face.\& /\ex{263b}/         # Same, the hex digits A \- F are case insensitive..Ve.Sh "Modifiers".IX Subsection "Modifiers"A number of backslash sequences have to do with changing the character,or characters following them. \f(CW\*(C`\el\*(C'\fR will lowercase the character followingit, while \f(CW\*(C`\eu\*(C'\fR will uppercase (or, more accurately, titlecase) thecharacter following it. (They perform similar functionality as thefunctions \f(CW\*(C`lcfirst\*(C'\fR and \f(CW\*(C`ucfirst\*(C'\fR)..PPTo uppercase or lowercase several characters, one might want to use\&\f(CW\*(C`\eL\*(C'\fR or \f(CW\*(C`\eU\*(C'\fR, which will lowercase/uppercase all characters followingthem, until either the end of the pattern, or the next occurrence of\&\f(CW\*(C`\eE\*(C'\fR, whatever comes first. They perform similar functionality as thefunctions \f(CW\*(C`lc\*(C'\fR and \f(CW\*(C`uc\*(C'\fR do..PP\&\f(CW\*(C`\eQ\*(C'\fR is used to escape all characters following, up to the next \f(CW\*(C`\eE\*(C'\fRor the end of the pattern. \f(CW\*(C`\eQ\*(C'\fR adds a backslash to any character thatisn't a letter, digit or underscore. This will ensure that any characterbetween \f(CW\*(C`\eQ\*(C'\fR and \f(CW\*(C`\eE\*(C'\fR is matched literally, and will not be interpretedby the regexp engine..PPMnemonic: \fIL\fRowercase, \fIU\fRppercase, \fIQ\fRuotemeta, \fIE\fRnd..PPExamples.IX Subsection "Examples".PP.Vb 7\& $sid     = "sid";\& $greg    = "GrEg";\& $miranda = "(Miranda)";\& $str     =~ /\eu$sid/;        # Matches \*(AqSid\*(Aq\& $str     =~ /\eL$greg/;       # Matches \*(Aqgreg\*(Aq\& $str     =~ /\eQ$miranda\eE/;  # Matches \*(Aq(Miranda)\*(Aq, as if the pattern\&                              #   had been written as /\e(Miranda\e)/.Ve.Sh "Character classes".IX Subsection "Character classes"Perl regular expressions have a large range of character classes. Some ofthe character classes are written as a backslash sequence. We will brieflydiscuss those here; full details of character classes can be found inperlrecharclass..PP\&\f(CW\*(C`\ew\*(C'\fR is a character class that matches any \fIword\fR character (letters,digits, underscore). \f(CW\*(C`\ed\*(C'\fR is a character class that matches any digit,while the character class \f(CW\*(C`\es\*(C'\fR matches any white space character.New in perl 5.10.0 are the classes \f(CW\*(C`\eh\*(C'\fR and \f(CW\*(C`\ev\*(C'\fR which match horizontaland vertical white space characters..PPThe uppercase variants (\f(CW\*(C`\eW\*(C'\fR, \f(CW\*(C`\eD\*(C'\fR, \f(CW\*(C`\eS\*(C'\fR, \f(CW\*(C`\eH\*(C'\fR, and \f(CW\*(C`\eV\*(C'\fR) arecharacter classes that match any character that isn't a word character,digit, white space, horizontal white space or vertical white space..PPMnemonics: \fIw\fRord, \fId\fRigit, \fIs\fRpace, \fIh\fRorizontal, \fIv\fRertical..PP\fIUnicode classes\fR.IX Subsection "Unicode classes".PP\&\f(CW\*(C`\epP\*(C'\fR (where \f(CW\*(C`P\*(C'\fR is a single letter) and \f(CW\*(C`\ep{Property}\*(C'\fR are used tomatch a character that matches the given Unicode property; propertiesinclude things like \*(L"letter\*(R", or \*(L"thai character\*(R". Capitalizing thesequence to \f(CW\*(C`\ePP\*(C'\fR and \f(CW\*(C`\eP{Property}\*(C'\fR make the sequence match a characterthat doesn't match the given Unicode property. For more details, see\&\*(L"Backslashed sequences\*(R" in perlrecharclass and\&\*(L"Unicode Character Properties\*(R" in perlunicode..PPMnemonic: \fIp\fRroperty..Sh "Referencing".IX Subsection "Referencing"If capturing parenthesis are used in a regular expression, we can referto the part of the source string that was matched, and match exactly thesame thing. There are three ways of referring to such \fIbackreference\fR:absolutely, relatively, and by name..PP\fIAbsolute referencing\fR.IX Subsection "Absolute referencing".PPA backslash sequence that starts with a backslash and is followed by anumber is an absolute reference (but be aware of the caveat mentioned above).If the number is \fIN\fR, it refers to the Nth set of parenthesis \- whateverhas been matched by that set of parenthesis has to be matched by the \f(CW\*(C`\eN\*(C'\fRas well..PPExamples.IX Subsection "Examples".PP.Vb 2\& /(\ew+) \e1/;    # Finds a duplicated word, (e.g. "cat cat").\& /(.)(.)\e2\e1/;  # Match a four letter palindrome (e.g. "ABBA")..Ve.PP\fIRelative referencing\fR.IX Subsection "Relative referencing".PPNew in perl 5.10.0 is a different way of referring to capture buffers: \f(CW\*(C`\eg\*(C'\fR.\&\f(CW\*(C`\eg\*(C'\fR takes a number as argument, with the number in curly braces (thebraces are optional). If the number (N) does not have a sign, it's a referenceto the Nth capture group (so \f(CW\*(C`\eg{2}\*(C'\fR is equivalent to \f(CW\*(C`\e2\*(C'\fR \- except that\&\f(CW\*(C`\eg\*(C'\fR always refers to a capture group and will never be seen as an octalescape). If the number is negative, the reference is relative, referring tothe Nth group before the \f(CW\*(C`\eg{\-N}\*(C'\fR..PPThe big advantage of \f(CW\*(C`\eg{\-N}\*(C'\fR is that it makes it much easier to writepatterns with references that can be interpolated in larger patterns,even if the larger pattern also contains capture groups..PPMnemonic: \fIg\fRroup..PPExamples.IX Subsection "Examples".PP.Vb 7\& /(A)        # Buffer 1\&  (          # Buffer 2\&    (B)      # Buffer 3\&    \eg{\-1}   # Refers to buffer 3 (B)\&    \eg{\-3}   # Refers to buffer 1 (A)\&  )\& /x;         # Matches "ABBA".\&\& my $qr = qr /(.)(.)\eg{\-2}\eg{\-1}/;  # Matches \*(Aqabab\*(Aq, \*(Aqcdcd\*(Aq, etc.\& /$qr$qr/                           # Matches \*(Aqababcdcd\*(Aq..Ve.PP\fINamed referencing\fR.IX Subsection "Named referencing".PPAlso new in perl 5.10.0 is the use of named capture buffers, which can bereferred to by name. This is done with \f(CW\*(C`\eg{name}\*(C'\fR, which is abackreference to the capture buffer with the name \fIname\fR..PPTo be compatible with .Net regular expressions, \f(CW\*(C`\eg{name}\*(C'\fR may also bewritten as \f(CW\*(C`\ek{name}\*(C'\fR, \f(CW\*(C`\ek<name>\*(C'\fR or \f(CW\*(C`\ek\*(Aqname\*(Aq\*(C'\fR..PPNote that \f(CW\*(C`\eg{}\*(C'\fR has the potential to be ambiguous, as it could be a namedreference, or an absolute or relative reference (if its argument is numeric).However, names are not allowed to start with digits, nor are allowed tocontain a hyphen, so there is no ambiguity..PPExamples.IX Subsection "Examples".PP.Vb 5\& /(?<word>\ew+) \eg{word}/ # Finds duplicated word, (e.g. "cat cat")\& /(?<word>\ew+) \ek{word}/ # Same.\& /(?<word>\ew+) \ek<word>/ # Same.\& /(?<letter1>.)(?<letter2>.)\eg{letter2}\eg{letter1}/\&                         # Match a four letter palindrome (e.g. "ABBA").Ve.Sh "Assertions".IX Subsection "Assertions"Assertions are conditions that have to be true \*(-- they don't actuallymatch parts of the substring. There are six assertions that are written asbackslash sequences..IP "\eA" 4.IX Item "A"\&\f(CW\*(C`\eA\*(C'\fR only matches at the beginning of the string. If the \f(CW\*(C`/m\*(C'\fR modifierisn't used, then \f(CW\*(C`/\eA/\*(C'\fR is equivalent with \f(CW\*(C`/^/\*(C'\fR. However, if the \f(CW\*(C`/m\*(C'\fRmodifier is used, then \f(CW\*(C`/^/\*(C'\fR matches internal newlines, but the meaningof \f(CW\*(C`/\eA/\*(C'\fR isn't changed by the \f(CW\*(C`/m\*(C'\fR modifier. \f(CW\*(C`\eA\*(C'\fR matches at the beginningof the string regardless whether the \f(CW\*(C`/m\*(C'\fR modifier is used..IP "\ez, \eZ" 4.IX Item "z, Z"\&\f(CW\*(C`\ez\*(C'\fR and \f(CW\*(C`\eZ\*(C'\fR match at the end of the string. If the \f(CW\*(C`/m\*(C'\fR modifier isn'tused, then \f(CW\*(C`/\eZ/\*(C'\fR is equivalent with \f(CW\*(C`/$/\*(C'\fR, that is, it matches at theend of the string, or before the newline at the end of the string. If the\&\f(CW\*(C`/m\*(C'\fR modifier is used, then \f(CW\*(C`/$/\*(C'\fR matches at internal newlines, but themeaning of \f(CW\*(C`/\eZ/\*(C'\fR isn't changed by the \f(CW\*(C`/m\*(C'\fR modifier. \f(CW\*(C`\eZ\*(C'\fR matches atthe end of the string (or just before a trailing newline) regardless whetherthe \f(CW\*(C`/m\*(C'\fR modifier is used..Sp\&\f(CW\*(C`\ez\*(C'\fR is just like \f(CW\*(C`\eZ\*(C'\fR, except that it will not match before a trailingnewline. \f(CW\*(C`\ez\*(C'\fR will only match at the end of the string \- regardless of themodifiers used, and not before a newline..IP "\eG" 4.IX Item "G"\&\f(CW\*(C`\eG\*(C'\fR is usually only used in combination with the \f(CW\*(C`/g\*(C'\fR modifier. If the\&\f(CW\*(C`/g\*(C'\fR modifier is used (and the match is done in scalar context), Perl willremember where in the source string the last match ended, and the next time,it will start the match from where it ended the previous time..Sp\&\f(CW\*(C`\eG\*(C'\fR matches the point where the previous match ended, or the beginningof the string if there was no previous match..SpMnemonic: \fIG\fRlobal..IP "\eb, \eB" 4.IX Item "b, B"\&\f(CW\*(C`\eb\*(C'\fR matches at any place between a word and a non-word character; \f(CW\*(C`\eB\*(C'\fRmatches at any place between characters where \f(CW\*(C`\eb\*(C'\fR doesn't match. \f(CW\*(C`\eb\*(C'\fRand \f(CW\*(C`\eB\*(C'\fR assume there's a non-word character before the beginning and afterthe end of the source string; so \f(CW\*(C`\eb\*(C'\fR will match at the beginning (or end)of the source string if the source string begins (or ends) with a wordcharacter. Otherwise, \f(CW\*(C`\eB\*(C'\fR will match..SpMnemonic: \fIb\fRoundary..PPExamples.IX Subsection "Examples".PP.Vb 4\&  "cat"   =~ /\eAcat/;     # Match.\&  "cat"   =~ /cat\eZ/;     # Match.\&  "cat\en" =~ /cat\eZ/;     # Match.\&  "cat\en" =~ /cat\ez/;     # No match.\&\&  "cat"   =~ /\ebcat\eb/;   # Matches.\&  "cats"  =~ /\ebcat\eb/;   # No match.\&  "cat"   =~ /\ebcat\eB/;   # No match.\&  "cats"  =~ /\ebcat\eB/;   # Match.\&\&  while ("cat dog" =~ /(\ew+)/g) {\&      print $1;           # Prints \*(Aqcatdog\*(Aq\&  }\&  while ("cat dog" =~ /\eG(\ew+)/g) {\&      print $1;           # Prints \*(Aqcat\*(Aq\&  }.Ve.Sh "Misc".IX Subsection "Misc"Here we document the backslash sequences that don't fall in one of thecategories above. They are:.IP "\eC" 4.IX Item "C"\&\f(CW\*(C`\eC\*(C'\fR always matches a single octet, even if the source string is encodedin \s-1UTF\-8\s0 format, and the character to be matched is a multi-octet character.\&\f(CW\*(C`\eC\*(C'\fR was introduced in perl 5.6..SpMnemonic: o\fIC\fRtet..IP "\eK" 4.IX Item "K"This is new in perl 5.10.0. Anything that is matched left of \f(CW\*(C`\eK\*(C'\fR isnot included in \f(CW$&\fR \- and will not be replaced if the pattern isused in a substitution. This will allow you to write \f(CW\*(C`s/PAT1 \eK PAT2/REPL/x\*(C'\fRinstead of \f(CW\*(C`s/(PAT1) PAT2/${1}REPL/x\*(C'\fR or \f(CW\*(C`s/(?<=PAT1) PAT2/REPL/x\*(C'\fR..SpMnemonic: \fIK\fReep..IP "\eR" 4.IX Item "R"\&\f(CW\*(C`\eR\*(C'\fR matches a \fIgeneric newline\fR, that is, anything that is considereda newline by Unicode. This includes all characters matched by \f(CW\*(C`\ev\*(C'\fR(vertical white space), and the multi character sequence \f(CW"\ex0D\ex0A"\fR(carriage return followed by a line feed, aka the network newline, orthe newline used in Windows text files). \f(CW\*(C`\eR\*(C'\fR is equivalent with\&\f(CW\*(C`(?>\ex0D\ex0A)|\ev)\*(C'\fR. Since \f(CW\*(C`\eR\*(C'\fR can match a more than one character,it cannot be put inside a bracketed character class; \f(CW\*(C`/[\eR]/\*(C'\fR is an error.\&\f(CW\*(C`\eR\*(C'\fR was introduced in perl 5.10.0..SpMnemonic: none really. \f(CW\*(C`\eR\*(C'\fR was picked because \s-1PCRE\s0 already uses \f(CW\*(C`\eR\*(C'\fR,and more importantly because Unicode recommends such a regular expressionmetacharacter, and suggests \f(CW\*(C`\eR\*(C'\fR as the notation..IP "\eX" 4.IX Item "X"This matches an extended Unicode \fIcombining character sequence\fR, andis equivalent to \f(CW\*(C`(?>\ePM\epM*)\*(C'\fR. \f(CW\*(C`\ePM\*(C'\fR matches any character that isnot considered a Unicode mark character, while \f(CW\*(C`\epM\*(C'\fR matches any characterthat is considered a Unicode mark character; so \f(CW\*(C`\eX\*(C'\fR matches any nonmark character followed by zero or more mark characters. Mark charactersinclude (but are not restricted to) \fIcombining characters\fR and\&\fIvowel signs\fR..Sp\&\f(CW\*(C`\eX\*(C'\fR matches quite well what normal (non-Unicode-programmer) usagewould consider a single character: for example a base character(the \f(CW\*(C`\ePM\*(C'\fR above), for example a letter, followed by zero or morediacritics, which are \fIcombining characters\fR (the \f(CW\*(C`\epM*\*(C'\fR above)..SpMnemonic: e\fIX\fRtended Unicode character..PPExamples.IX Subsection "Examples".PP.Vb 1\& "\ex{256}" =~ /^\eC\eC$/;    # Match as chr (256) takes 2 octets in UTF\-8.\&\& $str =~ s/foo\eKbar/baz/g; # Change any \*(Aqbar\*(Aq following a \*(Aqfoo\*(Aq to \*(Aqbaz\*(Aq.\& $str =~ s/(.)\eK\e1//g;     # Delete duplicated characters.\&\& "\en"   =~ /^\eR$/;         # Match, \en   is a generic newline.\& "\er"   =~ /^\eR$/;         # Match, \er   is a generic newline.\& "\er\en" =~ /^\eR$/;         # Match, \er\en is a generic newline.\&\& "P\ex{0307}" =~ /^\eX$/     # \eX matches a P with a dot above..Ve

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -