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.
次のような文字列がある場合:
"_test_teste2 _test3"
_前にスペースがなく、文字列の先頭にない前にスペースを追加するにはどうすればよいですか?
_
元:
"_test _teste2 _test3"
私はこれを試しました:
todo.desc = todo.desc.gsub /_/, " _"
動作しますが、すべての後にスペースを追加して_ください。
前もって感謝します。
>> "_abc_de _e _f_tes_fefe".gsub(/(\S)_/,'\1 _') => "_abc _de _e _f _tes _fefe"