Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
どうすればこれを置き換えることができますか?
lyrics = lyrics.gsub(/\n/,'').gsub(/^\{\"similar\": \[/, '').gsub(/\]\}$/, '').gsub(/^\{/, '').gsub(/\}$/, '')
より短いものと1つのgsub呼び出しに?
|代替シンボルを使用して正規表現にブランチを作成することにより、複数の正規表現を1つに結合できます。^、などのアンカーに注意して$ください。これらが1つのブランチに表示される場合、それらはそのブランチでのみ機能し、正規表現全体では機能しないためです。
|
^
$
lyrics = lyrics.gsub(/\n|^\{\"similar\": \[|\]\}$|^\{|\}$/, '')