Tbpgr Blog

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

書籍 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})\1/,"@") #=>"12age@age1234age"