Tbpgr Blog

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

2012-05-29から1日間の記事一覧

書籍 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) #=>…