====== Regular Expressions ====== * [[https://github.com/ziishaned/learn-regex/blob/master/translations/README-cn.md|Learn regex]] * [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions|MDN的正则表达式指南]] * 在线正则测试: * [[http://leaverou.github.io/regexplained/|Regexplained]] * [[http://www.regexplanet.com/|Regexplanet]] * [[http://www.debuggex.com/|Debuggex]] * [[http://regexcrossword.com/|Help to learn regex]] * [[http://regexper.com/|Regexper]] * 在线编辑正则: * [[https://github.com/Bowen7/regex-vis|Regex-vis]] * [[https://github.com/geongeorge/i-hate-regex|I hate regex]] * [[http://scriptular.com/|Scriptular]] * [[http://txt2re.com/|Txt2re]] * [[http://www.phpliveregex.com/|Php reg edit]] * duckduckgo.com's answer: Anchors ^ Start of string or line \A Start of string $ End of string or line \Z End of string \b Word boundary \B Not word boundary \< Start of word \> End of word Character Classes \c Control character \s Whitespace \S Not Whitespace \d Digit \D Not digit \w Word \W Not Word \x Hexadecimal digit \O Octal Digit POSIX Classes [:upper:] Uppercase letters [A-Z] [:lower:] Lowercase letters [a-z] [:alpha:] All letters [A-Za-z] [:alnum:] Digits and letters [A-Za-z0-9] [:digit:] Digits [0-9] [:xdigit:] Hexadecimal digits [0-9a-f] [:punct:] Punctuation [:blank:] Space and tab [ \t] [:space:] Blank characters [ \t\r\n\v\f] [:cntrl:] Control characters [\x00-\x1F\x7F] [:graph:] Printed characters [\x21-\x7E] [:print:] Printed characters and spaces [\x20-\x7E] [:word:] Digits, letters and underscore [A-Za-z0-9_] Pattern Modifiers //g Global Match (all occurrences) //i Case-insensitive //m Multiple line //s Treat string as single line //x Allow comments and whitespace //e Evaluate replacement //U Ungreedy pattern Escape Sequences \ Escape following character \Q Begin literal sequence \E End literal sequence Quantifiers * 0 or more + 1 or more ? 0 or 1 (optional) {3} Exactly 3 {3,} 3 or more {2,5} 2, 3, 4 or 5 Groups and Ranges . Any character except newline (\n) (a|b) a or b (...) Group (?:...) Passive (non-capturing) group [abc] Single character (a or b or c) [^abc] Single character (not a or b or c) [a-q] Single character range (a or b ... or q) [A-Z] Single character range (A or B ... or Z) [0-9] Single digit from 0 to 9 Assertions ?= Lookahead assertion ?! Negative lookahead ?<= Lookbehind assertion ?!= or ? Once-only Subexpression ?() Condition [if then] ?()| Condition [if then else] ?# Comment Special Characters \n New line \r Carriage return \t Tab \v Vertical tab \f Form feed \ooo Octal character ooo \xhh Hex character hh String Replacement $n n-th non-passive group $2 "xyz" in /^(abc(xyz))$/ $1 "xyz" in /^(?:abc)(xyz)$/ $` Before matched string $' After matched string $+ Last matched string $& Entire matched string