Skip to content

Instantly share code, notes, and snippets.

@songxiaofeng1981
Created November 16, 2012 14:16
Show Gist options
  • Save songxiaofeng1981/4087668 to your computer and use it in GitHub Desktop.
Save songxiaofeng1981/4087668 to your computer and use it in GitHub Desktop.
RegRex:lookbehind all
# Lookaheads
jeffrey@envato.com
jeffrey@jeffrey-way.com
jeffrey@envato.edu
jeffrey@jeffrey-way.au
jeffrey@jeffrey-way.tv
正则匹配表达式: @.+(?=\.[a-z]{2,4})
解释:
@ 匹配@
. 匹配任意字符
\.[a-z]{2,4} \.匹配一个 . , [a-z] 匹配所有小写字母 {2,4} 匹配小写字母2-4次。
(?=)匹配但不包含上面的匹配结果
# negative lookahead matching
joe@envato.com
jeffrey@jeffrey-way.com
jeffrey@envato.edu
jeffrey@jeffrey-way.au
jeffrey@jeffrey-way.tv
正则匹配表达式:(?<!jeffrey)@.+
解释:
(?<!jeffrey)匹配前面不包含jeffrey的行,上面示例结果为
@envato.com
# Positive lookbehind matching
只需把前面(?<!)
# Positive lookahead.
box-sizeing
box-shadow
正则匹配表达式: box(?=-shadow)
解释:
只匹配后面有 -shadow 的字符,但不包含
# Negative lookbehind matching
box-sizeing
box-shadow
正则匹配表达式: box(?!-shadow)
解释:
只匹配后面不包含 -shadow 的字符
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment