Skip to content

Instantly share code, notes, and snippets.

@liushooter
Forked from luikore/space_en_ch.rb
Created December 4, 2013 08:46
Show Gist options
  • Save liushooter/7784320 to your computer and use it in GitHub Desktop.
Save liushooter/7784320 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
str = $stdin.read
if RUBY_VERSION < '1.9'
print str
exit
end
str.force_encoding 'utf-8'
str.gsub! /(\p{Han})([a-zA-Z0-9\(\)\[\]\{\}])/u do
"#$1 #$2"
end
str.gsub! /([a-zA-Z0-9\(\)\[\]\{\}])(\p{Han})/u do
"#$1 #$2"
end
print str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment