Created
February 3, 2012 09:22
-
-
Save tikitikipoo/1729220 to your computer and use it in GitHub Desktop.
(左から数えて)指定した語句Aの直近にある語句Bから取得する正規表現
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 例: | |
// 目標:以下の文字列の中から_m.jpgで終わるURLを取得 | |
// 表題に合わせると「(左から数えて)_m.jpgの直近にあるhttpから取得する」 | |
// 参考:http://www.geocities.jp/oraclesqlpuzzle/regex/regex-4-28.html | |
var tmp = 'http://f.hatena.ne.jp/memi811/20120124082636<a href="http://f.hatena.ne.jp/memi811/20120124082636"><img src="http://cdn-ak.f.st-hatena.com/images/fotolife/m/memi811/20120124/20120124082636_m.jpg" alt="20120124082636"></a><a href="http://f.hatena.ne.jp/memi811/20120124082636"><img src="http://cdn-ak.f.st-hatena.com/images/fotolife/m/memi811/20120124/20120124082636.jpg" alt="20120124082636"></a>2012-01-24T08:26:36+09:00http://cdn-ak.f.st-hatena.com/images/fotolife/m/memi811/20120124/20120124082636.jpghttp://cdn-ak.f.st-hatena.com/images/fotolife/m/memi811/20120124/20120124082636_m.jpghttp://cdn-ak.f.st-hatena.com/images/fotolife/m/memi811/20120124/20120124082636_120.jpg'; | |
console.log( tmp.match(/http(.(?!http))*_m\.jpg/)[0] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment