Tbpgr Blog

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

書籍 Regular Expressions Cookbook | Escape Regular Expression Metacharacters

パンくず

書籍 Regular Expressions Cookbook
Escape Regular Expression Metacharacters

概要

正規表現のエスケープについて

サンプル

str = '\n[]|^!?+'
puts str
puts "-------------------------"
puts Regexp.escape(str)

出力

\n[]|^!?+
-------------------------
\\n\[\]\|\^!\?\+