Skip to content

Instantly share code, notes, and snippets.

@yuyay
Created October 5, 2012 07:54
Show Gist options
  • Save yuyay/3838642 to your computer and use it in GitHub Desktop.
Save yuyay/3838642 to your computer and use it in GitHub Desktop.
RTの発信元を抽出する正規表現
import re
r = re.compile("RT @([0-9a-zA-Z_]{1,15}):(?!.*RT @[0-9a-zA-Z_]{1,15})\s?(.*?)$")
text = "RT @aaa: あああ RT @bbb: いいい"
s = r.search(text)
s.group(0) # マッチした全体(RT @bbb: いいい)
s.group(1) # 発信者screen_name(bbb)
s.group(2) # 発信情報(いいい)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment