速记
大句哥哥 (make pie, or invent universe)
- 章节名:速记
- 2013-05-23 09:14:57
[0-9] The square brackets are not literally matched because they are treated specially as metacharacters. character escape would lead to misleading, try to avoid it: not always supported and less flexibility of character class. Use digit character class. \D = [^0-9] = [^\d] \w = [0-9a-zA-Z], \W = [^\w] enclose regex in a pair of parenthesis to place it in a group, and use \1 to back reference it. like (\d)0\1 -> 707 or g/(word1)(word2)/\2 \1/ enclose digit in a pair of curly brace to describe last regex's occurrences. enclose a set of characters (or character class) by `[]` some quantifiers: . * ? + alternation: | ^$ dotall means a dot will match all characters, including newlines. ^.* with dotall mode will match whole text. word boundaries: \bword\b, \<word\> (older syntax, may not be avail in recent applications), \Aword\Z (Perl and PCRE) Quoting a Group of Characters as Literals: \Q$\E, or \$ (.^$*+?|(){}[]\-) (?i) case insensitive; (?m) multiple line; (?s) single line / dotline; (?x) ignore whitespace ??? (?<named_group>pattern) and $+{named_group} to back reference; use (?<name>pattern)aaaaaa<name> to reuse. ###### by language…….. (?:the|The|THE) non-capturing groups: do not need to store in memory. (?>the) to turn off backtracking. Greedy (try to match whole string), Lazy, and Possessive ( one attempt) ? Zero or one (optional) + One or more * Zero or more {n} Match n times exactly {n,} Match n or more times {m,n} Match m to n times {0,1} Same as ? (zero or one) {1,0} Same as + (one or more) {0,} Same as * (zero or more) ?? Lazy zero or one (optional) +? Lazy one or more *? Lazy zero or more {n}? Lazy n {n,}? Lazy n or more {m,n}? Lazy m,n Positive Lookaheads: time (?=results) #=> find out 'time' in 'time result' (((((( try it in ack/ag or negative lookaheads: (?!results) positive lookbehinds: (?<=time) result Negative Lookbehinds: (?1)(?<!ancyent) marinere % ack -i 'return (?=os)' ark_wsgi.py return os.popen(filename[1:], 'w', 1) % ack -i '(?<=os).popen' ark_wsgi.py return os.popen(filename[1:], 'w', 1) matching html start tags: <[_a-zA-Z][^>]*> Glossary pesky wildcard parenthesis - parentheses caret decipher Is your head spinning? gobble nibble archaic
说明 · · · · · ·
表示其中内容是对原文的摘抄