📄 perlreref.1
字号:
.PPFor Titlecase, see \*(L"Titlecase\*(R"..PPThis one works differently from normal strings:.PP.Vb 1\& \eb An assertion, not backspace, except in a character class.Ve.Sh "\s-1CHARACTER\s0 \s-1CLASSES\s0".IX Subsection "CHARACTER CLASSES".Vb 4\& [amy] Match \*(Aqa\*(Aq, \*(Aqm\*(Aq or \*(Aqy\*(Aq\& [f\-j] Dash specifies "range"\& [f\-j\-] Dash escaped or at start or end means \*(Aqdash\*(Aq\& [^f\-j] Caret indicates "match any character _except_ these".Ve.PPThe following sequences work within or without a character class.The first six are locale aware, all are Unicode aware. See perllocaleand perlunicode for details..PP.Vb 11\& \ed A digit\& \eD A nondigit\& \ew A word character\& \eW A non\-word character\& \es A whitespace character\& \eS A non\-whitespace character\& \eh An horizontal white space\& \eH A non horizontal white space\& \ev A vertical white space\& \eV A non vertical white space\& \eR A generic newline (?>\ev|\ex0D\ex0A)\&\& \eC Match a byte (with Unicode, \*(Aq.\*(Aq matches a character)\& \epP Match P\-named (Unicode) property\& \ep{...} Match Unicode property with long name\& \ePP Match non\-P\& \eP{...} Match lack of Unicode property with long name\& \eX Match extended Unicode combining character sequence.Ve.PP\&\s-1POSIX\s0 character classes and their Unicode and Perl equivalents:.PP.Vb 10\& alnum IsAlnum Alphanumeric\& alpha IsAlpha Alphabetic\& ascii IsASCII Any ASCII char\& blank IsSpace [ \et] Horizontal whitespace (GNU extension)\& cntrl IsCntrl Control characters\& digit IsDigit \ed Digits\& graph IsGraph Alphanumeric and punctuation\& lower IsLower Lowercase chars (locale and Unicode aware)\& print IsPrint Alphanumeric, punct, and space\& punct IsPunct Punctuation\& space IsSpace [\es\eck] Whitespace\& IsSpacePerl \es Perl\*(Aqs whitespace definition\& upper IsUpper Uppercase chars (locale and Unicode aware)\& word IsWord \ew Alphanumeric plus _ (Perl extension)\& xdigit IsXDigit [0\-9A\-Fa\-f] Hexadecimal digit.Ve.PPWithin a character class:.PP.Vb 3\& POSIX traditional Unicode\& [:digit:] \ed \ep{IsDigit}\& [:^digit:] \eD \eP{IsDigit}.Ve.Sh "\s-1ANCHORS\s0".IX Subsection "ANCHORS"All are zero-width assertions..PP.Vb 8\& ^ Match string start (or line, if /m is used)\& $ Match string end (or line, if /m is used) or before newline\& \eb Match word boundary (between \ew and \eW)\& \eB Match except at word boundary (between \ew and \ew or \eW and \eW)\& \eA Match string start (regardless of /m)\& \eZ Match string end (before optional newline)\& \ez Match absolute string end\& \eG Match where previous m//g left off\&\& \eK Keep the stuff left of the \eK, don\*(Aqt include it in $&.Ve.Sh "\s-1QUANTIFIERS\s0".IX Subsection "QUANTIFIERS"Quantifiers are greedy by default \*(-- match the \fBlongest\fR leftmost..PP.Vb 9\& Maximal Minimal Possessive Allowed range\& \-\-\-\-\-\-\- \-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\-\-\-\& {n,m} {n,m}? {n,m}+ Must occur at least n times\& but no more than m times\& {n,} {n,}? {n,}+ Must occur at least n times\& {n} {n}? {n}+ Must occur exactly n times\& * *? *+ 0 or more times (same as {0,})\& + +? ++ 1 or more times (same as {1,})\& ? ?? ?+ 0 or 1 time (same as {0,1}).Ve.PPThe possessive forms (new in Perl 5.10) prevent backtracking: what getsmatched by a pattern with a possessive quantifier will not be backtrackedinto, even if that causes the whole match to fail..PPThere is no quantifier {,n} \*(-- that gets understood as a literal string..Sh "\s-1EXTENDED\s0 \s-1CONSTRUCTS\s0".IX Subsection "EXTENDED CONSTRUCTS".Vb 10\& (?#text) A comment\& (?:...) Groups subexpressions without capturing (cluster)\& (?pimsx\-imsx:...) Enable/disable option (as per m// modifiers)\& (?=...) Zero\-width positive lookahead assertion\& (?!...) Zero\-width negative lookahead assertion\& (?<=...) Zero\-width positive lookbehind assertion\& (?<!...) Zero\-width negative lookbehind assertion\& (?>...) Grab what we can, prohibit backtracking\& (?|...) Branch reset\& (?<name>...) Named capture\& (?\*(Aqname\*(Aq...) Named capture\& (?P<name>...) Named capture (python syntax)\& (?{ code }) Embedded code, return value becomes $^R\& (??{ code }) Dynamic regex, return value used as regex\& (?N) Recurse into subpattern number N\& (?\-N), (?+N) Recurse into Nth previous/next subpattern\& (?R), (?0) Recurse at the beginning of the whole pattern\& (?&name) Recurse into a named subpattern\& (?P>name) Recurse into a named subpattern (python syntax)\& (?(cond)yes|no)\& (?(cond)yes) Conditional expression, where "cond" can be:\& (N) subpattern N has matched something\& (<name>) named subpattern has matched something\& (\*(Aqname\*(Aq) named subpattern has matched something\& (?{code}) code condition\& (R) true if recursing\& (RN) true if recursing into Nth subpattern\& (R&name) true if recursing into named subpattern\& (DEFINE) always false, no no\-pattern allowed.Ve.Sh "\s-1VARIABLES\s0".IX Subsection "VARIABLES".Vb 1\& $_ Default variable for operators to use\&\& $\` Everything prior to matched string\& $& Entire matched string\& $\*(Aq Everything after to matched string\&\& ${^PREMATCH} Everything prior to matched string\& ${^MATCH} Entire matched string\& ${^POSTMATCH} Everything after to matched string.Ve.PPThe use of \f(CW\*(C`$\`\*(C'\fR, \f(CW$&\fR or \f(CW\*(C`$\*(Aq\*(C'\fR will slow down \fBall\fR regex usewithin your program. Consult perlvar for \f(CW\*(C`@\-\*(C'\fRto see equivalent expressions that won't cause slow down.See also Devel::SawAmpersand. Starting with Perl 5.10, youcan also use the equivalent variables \f(CW\*(C`${^PREMATCH}\*(C'\fR, \f(CW\*(C`${^MATCH}\*(C'\fRand \f(CW\*(C`${^POSTMATCH}\*(C'\fR, but for them to be defined, you have tospecify the \f(CW\*(C`/p\*(C'\fR (preserve) modifier on your regular expression..PP.Vb 8\& $1, $2 ... hold the Xth captured expr\& $+ Last parenthesized pattern match\& $^N Holds the most recently closed capture\& $^R Holds the result of the last (?{...}) expr\& @\- Offsets of starts of groups. $\-[0] holds start of whole match\& @+ Offsets of ends of groups. $+[0] holds end of whole match\& %+ Named capture buffers\& %\- Named capture buffers, as array refs.Ve.PPCaptured groups are numbered according to their \fIopening\fR paren..Sh "\s-1FUNCTIONS\s0".IX Subsection "FUNCTIONS".Vb 4\& lc Lowercase a string\& lcfirst Lowercase first char of a string\& uc Uppercase a string\& ucfirst Titlecase first char of a string\&\& pos Return or set current match position\& quotemeta Quote metacharacters\& reset Reset ?pattern? status\& study Analyze string for optimizing matching\&\& split Use a regex to split a string into parts.Ve.PPThe first four of these are like the escape sequences \f(CW\*(C`\eL\*(C'\fR, \f(CW\*(C`\el\*(C'\fR,\&\f(CW\*(C`\eU\*(C'\fR, and \f(CW\*(C`\eu\*(C'\fR. For Titlecase, see \*(L"Titlecase\*(R"..Sh "\s-1TERMINOLOGY\s0".IX Subsection "TERMINOLOGY"\fITitlecase\fR.IX Subsection "Titlecase".PPUnicode concept which most often is equal to uppercase, but forcertain characters like the German \*(L"sharp s\*(R" there is a difference..SH "AUTHOR".IX Header "AUTHOR"Iain Truskett. Updated by the Perl 5 Porters..PPThis document may be distributed under the same terms as Perl itself..SH "SEE ALSO".IX Header "SEE ALSO".IP "\(bu" 4perlretut for a tutorial on regular expressions..IP "\(bu" 4perlrequick for a rapid tutorial..IP "\(bu" 4perlre for more details..IP "\(bu" 4perlvar for details on the variables..IP "\(bu" 4perlop for details on the operators..IP "\(bu" 4perlfunc for details on the functions..IP "\(bu" 4perlfaq6 for FAQs on regular expressions..IP "\(bu" 4perlrebackslash for a reference on backslash sequences..IP "\(bu" 4perlrecharclass for a reference on character classes..IP "\(bu" 4The re module to alter behaviour and aiddebugging..IP "\(bu" 4\&\*(L"Debugging regular expressions\*(R" in perldebug.IP "\(bu" 4perluniintro, perlunicode, charnames and perllocalefor details on regexes and internationalisation..IP "\(bu" 4\&\fIMastering Regular Expressions\fR by Jeffrey Friedl(\fIhttp://regex.info/\fR) for a thorough grounding andreference on the topic..SH "THANKS".IX Header "THANKS"David P.C. Wollmann,Richard Soderberg,Sean M. Burke,Tom Christiansen,Jim Cromie,andJeffrey Gofffor useful advice.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -