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.
スペース文字 (\s) でもないすべての非単語文字 (\W) を置き換えるにはどうすればよいですか?
これは望ましい機能です:
"the (quick)! brown \n fox".gsub(regex, "#")
=>
"the #quick## brown \n fox"
"the (quick)! brown \n fox".gsub(/[^\w\s]/, "#")
正規表現を使用して、単語文字でもスペース文字でもないものをすべて置き換えます。
このような正規表現が必要だと思います。
/[^\w\s]/
文字セットの先頭に曲折アクセント記号を追加する^と、式が無効になり、セット内の文字以外のものがすべて一致します。
^