でワイルドカード:使用して、私はこのような何かをしたいと思いますGSUB
"String with text and replaceText and replaceText and so on... "
になり
"String with text and $abc$ and $def$ and so on... ".gsub("$*$", "replaceText")
しかし、私はわかりませんどのようにここに*
作品のようなワイルドカード。
でワイルドカード:使用して、私はこのような何かをしたいと思いますGSUB
"String with text and replaceText and replaceText and so on... "
になり
"String with text and $abc$ and $def$ and so on... ".gsub("$*$", "replaceText")
しかし、私はわかりませんどのようにここに*
作品のようなワイルドカード。
あなたがエスケープする必要があります
"String with text and $abc$ and $def$ and so on... ".gsub(/\$\w+\$/, "replaceText")
#=> "String with text and replaceText and replaceText and so on... "
は覚えておいてください。この目的のために正規表現を使用することができます$
"String with text and $abc$ and $def$ and so on... ".gsub(/\$\w+\$/, "replaceText")
試してみてください\ $ \ワット+ \ $でhttp://rubular.com/
ただ好奇心から:1つはより多くのデリミタを持っているかどうか(do彼女はback-referencesを使用する場合があります)、唯一のサインリャル:内部[]
$
(*
どちらをエスケープする必要はありません
str = "String with text and $abc$ and *def* and so on... "
str.gsub(/(?<delim>[$*]).*?\k<delim>/, "replaceText")
#⇒ "String with text and replaceText and replaceText and so on... "
注)
これは "ä"や "ü"のような特別なキャラクターでも動作します – kernification
発音記号を持つヨーロッパのアルファベットの文字でどのように使われるのか分かりません。 – mudasobwa
それはワイルドカードではありません。それはそのようには機能しません。 – sawa