24
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

文字列中の   (C2A0) を正規表現で削除

Last updated at Posted at 2015-01-23

スクレイピングなどしているとテキスト中に含まれている   によく遭遇します。
これは strip でも gsub(/\s/'') 等でも消せませんが、以下のようにすると削除できます。

 # 正規表現でPOSIX文字クラスを使う
inner_text.gsub(/[[:space:]]/)

 # 文字コード直接指定でもできる
inner_text.gsub(/\u{C2A0}/)  # gsub(/\uC2A0/) でもOK

 
リファレンスよく読めばかいてありますね。

ここを読んでピンと来ました。

24
23
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?