日暮途遠(Linux)

Just another WordPress.com site

ツイートのパーマリンク(固定URL)のユーザ名とIDを取得する正規表現(sed)

leave a comment »

参考:【 文字列を置換する「sed」 】 – シェル・スクリプト・リファレンス:ITpro.

ユーザ名を取得
sed -e ‘s/http:\/\/twitter.com\/\([^\/]\+\).*/\1/’

ツイートのIDを取得
sed -e ‘s/http:\/\/twitter.com.*status\/\([0-9]\+\)/\1/’

httpsの場合
ユーザ名を取得
sed -e ‘s/https:\/\/twitter.com\/#!\/\([^\/]\+\).*/\1/’

ツイートのIDを取得
sed -e ‘s/https:\/\/twitter.com.*status\/\([0-9]\+\)/\1/’

 Twitterのユーザ名はスクリーンネームという方が正確なのかもしれないです。パーマリンクは次のような形式になっています。(httpsをhttpsーに変更。これをしないとプラグインが処理を行ってしまいます。下のがそれです。)
httpsー://twitter.com/#!/hirono_hideki/status/103072478993195009

Written by 廣野秀樹

2011年8月15日 @ 9:56 午後

カテゴリー: bash

Tagged with

コメントを残す