Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

2012-05-01から1ヶ月間の記事一覧

書籍 Regular Expressions Cookbook | Validate Handy Phone Number

パンくず 書籍 Regular Expressions Cookbook Validate Handy Phone Number 概要 携帯電話番号のバリデーション サンプル subject = Array.new subject << "08012345678" subject << "090-1234-5678" subject << "070-1234-5678" subject << " 090-1234-5678…

書籍 Regular Expressions Cookbook | Search Line by Line

パンくず 書籍 Regular Expressions Cookbook Search Line by Line 概要 コマンドラインのように、各行に対して正規表現を行う方法について サンプル subject =<<"EOS" one two three EOS lines = subject.split(/\r?\n/) re = /two/ lines.each do |line| i…

書籍 Regular Expressions Cookbook | get start or end index

パンくず 書籍 Regular Expressions Cookbook get start or end index 概要 正規表現のマッチング結果の位置情報の取得 構文 利用する構文 ・マッチした内容を取得 $~ ・マッチした文字列の開始位置 $~.begin(0) ・マッチした文字列の終了位置 $~.end(0) サ…

書籍 Regular Expressions Cookbook | get left or right or match String

パンくず 書籍 Regular Expressions Cookbook get left or right or match String 概要 正規表現のマッチング結果の取得 構文 利用する構文 ・マッチした内容より前方を取得 $` ・マッチした内容を取得 $& ・マッチした内容より後方を取得 $' サンプル "Hoge…

書籍 Regular Expressions Cookbook | Eliminate Needless Backtracking

パンくず 書籍 Regular Expressions Cookbook Eliminate Needless Backtracking 概要 (独占的|絶対最大)量指定子について。 後戻りしてのマッチングをしない。 構文 /(target++)/ サンプル DragonQuestに対して、1文字以上の任意の文字(\w+)と(Quest)でマッ…

書籍 Regular Expressions Cookbook | Capture and Name Parts of the Match

パンくず 書籍 Regular Expressions Cookbook Capture and Name Parts of the Match 概要 名前付きキャプチャについて 構文 (?<name>regexp) # => 名前付き後方参照宣言 \k<name># => 名前付き後方参照利用 サンプル 後方参照にyear,month,dayという名前を付けて利用 tar</name></name>…

書籍 Regular Expressions Cookbook | Replace All Matches Within the Matches of Another Regex

パンくず 書籍 Regular Expressions Cookbook Replace All Matches Within the Matches of Another Regex 概要 正規表現で抽出した内容のうち、 更に別の正規表現に一致するもののみ置換する サンプル # タグの中の文字列がbeforeだった場合のみ置換する sub…

書籍 Regular Expressions Cookbook | Find a Match Within Another Match

パンくず 書籍 Regular Expressions Cookbook Find a Match Within Another Match 概要 マッチした内容を、更に別の条件にマッチさせる サンプル list = [] subject = "【124\n212\nhige】【hohoho 999】" # mは複数行モード subject.scan(/【(.*?)】/m) {|o…

書籍 Regular Expressions Cookbook | Retrieve a List of All Matches

パンくず 書籍 Regular Expressions Cookbook Retrieve a List of All Matches 概要 マッチした内容全体をリストで取得 構文 # 戻り値はヒットした件数分のリストになる ret = "reg".scan(/regexp/) サンプル subject = "hoge hige hage" result = subject.s…

書籍 Regular Expressions Cookbook | Insert the Regex Match into the Replacement Text

パンくず 書籍 Regular Expressions Cookbook Insert the Regex Match into the Replacement Text 概要 マッチングした内容を後方参照で置換文字列内に埋め込む方法について 構文 マッチ内容をグループのindexを指定して取得 string.gsub(/(pattern1)(patter…

書籍 Regular Expressions Cookbook | Insert the Regex Match into the Replacement Text

パンくず 書籍 Regular Expressions Cookbook Insert the Regex Match into the Replacement Text 概要 マッチングした内容を後方参照で置換文字列内に埋め込む方法について 構文 マッチ内容全体を参照 \0 サンプル URLをはてな記法のリンクにします。 # \S…

書籍 Regular Expressions Cookbook | Add Comments to a Regular Expression

パンくず 書籍 Regular Expressions Cookbook Add Comments to a Regular Expression 概要 正規表現でのコメントについて 構文 (?#comment) サンプル reg = /(?#family name)([A-Z][a-z]+)\s(?#first name)([A-Z][a-z]+)/ puts "Tanaka Hideo".scan(reg) #=>…

パフォーマンス オプティカルマウス G400購入

マウスを購入。 先代のBlue Focusが購入一ヶ月そこそこで壊れるという暴挙。 購入後にAmazonのレビューをみたら1〜2ヶ月で壊れたという人が多く嫌な予感がしていたら案の定。 結局PC付属の標準マウスで代用していたのだが、買い直すことを決意。 今回は失敗…

書籍 Regular Expressions Cookbook | Match Previously Matched Text Again

パンくず 書籍 Regular Expressions Cookbook Match Previously Matched Text Again 概要 前回一致した内容を再びマッチさせる方法について 構文 \b(\w)\1\b サンプル # 2文字の数値の繰り返しが出てきたら@に置換 pp "12age1212age1234age".gsub(/([\d]{2})…

書籍 Regular Expressions Cookbook | Group and Capture Parts of the Match

パンくず 書籍 Regular Expressions Cookbook Group and Capture Parts of the Match 概要 複数用語を1つのグループとしてマッチさせる方法について。 構文 Groups(複数の候補の中から一つだけでも一致すればマッチ) \b(one|two|three)\b Noncapturing gro…

書籍 Refactoring to Patterns | Utilities

パンくず 書籍 Refactoring to Patterns Utilities 概要 Utilities、ユーティリティーに関するリファクタリング ユーティリティーに関するリファクタリング Refactoring リファクタリング Chain Constructors コンストラクタの連鎖 Unity Interface インター…

書籍 Refactoring to Patterns | Accumulation| Move Accumulation to Visitor

パンくず 書籍 Refactoring to Patterns Accumulation Move Accumulation to Visitor 概要 Move Accumuration to Visitorについて 使用する場面 1つのメソッドが異種のオブジェクトから情報を累積する場合 対応方法 Visitorパターンを使用する 利点と欠点 利…

書籍 Refactoring to Patterns | Accumulation| Move Accumulation to Collecting Parameter

パンくず 書籍 Refactoring to Patterns Accumulation Move Accumulation to Collecting Parameter 概要 Move Accumulation to Collecting Parameterについて 使用する場面 一つのローカル変数に対する変更をまとめて行なっている一つのメソッドがあるなら、…

書籍 Refactoring to Patterns | Accumulation

パンくず 書籍 Refactoring to Patterns Accumulation 概要 Accumulation、蓄積に関するリファクタリング 蓄積に関するリファクタリング Refactoring リファクタリング Move Accumulation to Collectiing Parameter Collecting Parameterによる累積処理の書…

書籍 Productive Programmer | 怒れるサル

パンくず 書籍 Productive Programmer 怒れるサル 概要 怒れるサルについて 内容 怒れるサル とある実験に関するお話。 部屋に複数のサルを入れて、脚立と天井から吊るされたバナナが置いてあります。 サルは脚立に登ってバナナを取ろうとしますが、脚立に近…

書籍 Productive Programmer

概要 書籍 Productive Programmerに関するメモ 1章、2章 略 3章 集中 項目 内容 JediConcentrate カレントウインドウ以外を暗転することで集中力を上げる 4章〜10章 略 11章 権威を疑う 項目 内容 怒れるサル 組織の習慣を疑うこと 12章 メタプログラミング …

書籍 Refactoring to Patterns | Utilities | Extract Parameter

パンくず 書籍 Refactoring to Patterns Utilities Extract Parameter 概要 Extract Parameterについて 使用する場面 委譲の利用時に他のオブジェクトのインスタンス生成のための パラメータが必要な場合。 対応方法 Extract Parameterを適用する。 サンプル…

書籍 Refactoring to Patterns | Utilities | Unity Interface

パンくず 書籍 Refactoring to Patterns Utilities Unity Interface 概要 Unity Interfaceについて 使用する場面 複数の子クラスに、共通するシグニチャのメソッドがあるがインターフェース もしくは抽象基底クラスにインターフェースが用意されていない。 …

書籍 Refactoring to Patterns | Utilities | Chain Constructors

パンくず 書籍 Refactoring to Patterns Utilities Chain Constructors 概要 Chain Constructorsについて 使用する場面 複数のコンストラクタの内容が重複している。 対応方法 Chain Constructorsを適用する。 全体に共通するコンストラクタを用意し、各コン…

書籍 Refactoring to Patterns | Protection | Introduce Null Object

パンくず 書籍 Patterns to Patterns Protection Introduce Null Object 概要 Introduce Null Objectについて 使用する場面 大量のNullチェックがある場合 対応方法 Null Objectを導入します 利点と欠点 利点 ・Nullロジックの重複を防ぎ、Nullエラーを防ぐ …

秀丸のCSVモードで列選択を行う

概要 秀丸のCSVモードで列選択を行う 方法 メニューの表示→タブストップ→CSVモード でカンマ区切りのCSVファイルを見やすく表示した後に、 上部のルーラーをクリックすると、列選択が可能です。 Excelのように操作が可能。 画面 列選択前 列選択後

書籍 Refactoring to Patterns | Protection | Limit Instantiation with Singleton

パンくず 書籍 Patterns to Patterns Protection Limit Instantiation with Singleton 概要 Limit Instantiation with Singletonについて 使用する場面 パフォーマンスやメモリーの、都合でひとつのインスタンスにしたい場合 対応方法 Singletonパターンを適…

書籍 Regular Expressions Cookbook | Word Boundary

パンくず 書籍 Regular Expressions Cookbook Word Boundary 概要 単語境界にマッチングする方法について。 指定パターンの前後に区切り文字があるかどうかでマッチングを行う。 また、区切り文字がない場合のみマッチングを行う。 構文 単語境界(前) \bwo…

書籍 Regular Expressions Cookbook | Nonprinting characters table

パンくず 書籍 Regular Expressions Cookbook Nonprinting characters table 概要 非表示文字を正規表現で表す場合の一覧 表 文法 意味 \a bell \e escape \f form feed \n line feed(改行) \r carriage return \t horizontal tab(タブ) \v vertical tab(垂…

書籍 Regular Expressions Cookbook | Ignore Case (?i)ascii

パンくず 書籍 Regular Expressions Cookbook Ignore Case (?i)ascii 概要 大文字小文字を無視する方法について 構文 (?i)ascii サンプル require "pp" pp /(?i)hoge/ =~ "HoGe" pp /hoge/ =~ "HoGe" 結果 0 nil