タグ

2011年8月23日のブックマーク (2件)

  • JavaScript regex multiline text between two tags

    I wrote a regex to fetch string from HTML, but it seems the multiline flag doesn't work. This is my pattern and I want to get the text in h1 tag. var pattern= /<div class="box-content-5">.*<h1>([^<]+?)<\/h1>/mi m = html.search(pattern); return m[1]; I created a string to test it. When the string contains "\n", the result is always null. If I removed all the "\n"s, it gave me the right result, no m

    JavaScript regex multiline text between two tags
    mi_kattun
    mi_kattun 2011/08/23
    JavaScriptの正規表現にはピリオドを改行にマッチさせるフラグ(/.../s, dotall)がないので、[\s\S]などで代用する
  • UxUによるGreasemonkeyスクリプトのテスト - クリアコード

    概要 テストケースで利用可能なヘルパーメソッド 対応しているGM関数 イベントリスナによるイベントの捕捉 UxUの紹介ページに戻る UxU用のテストケースの書き方 アサーション一覧 テストケース内で利用可能なヘルパーメソッド モックを使ったテスト UxUをリモート操作する UxUのコマンドラインオプション 概要 テストケースの実行コンテキストではGM_xmlhttpRequest()などの代表的なGM関数を利用できます(利用可能なGM関数の一覧)。ヘルパーメソッドのutils.include()などを使用してGreasemonkeyスクリプトを読み込むことで、Greasemonkeyスクリプト内で定義された関数などのテストを行えます。 ※スクリプトの前後に(function() { ... })()のようなコードを加えている場合、スクリプト内で定義された関数などにアクセスできませんので、そ

    UxUによるGreasemonkeyスクリプトのテスト - クリアコード