Skip to content

Instantly share code, notes, and snippets.

@fjyuu fjyuu/spacing.pl
Created May 5, 2012

Embed
What would you like to do?
分かち書きしないっぽい文字を表す正規表現(User-Defined Character Properties)
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.010;
binmode STDOUT, ":utf8";
my $text = "これはpenです";
$text =~ s/(\p{IsNonSpacingCharacter})([^\p{IsNonSpacingCharacter}])/$1 $2/g;
$text =~ s/([^\p{IsNonSpacingCharacter}])(\p{IsNonSpacingCharacter})/$1 $2/g;
say $text; # これは pen です
sub IsNonSpacingCharacter {
return <<'END';
+utf8::Hiragana
+utf8::Katakana
+utf8::InKatakana
+utf8::Han
+utf8::InCJKSymbolsAndPunctuation
+utf8::InHalfwidthAndFullwidthForms
END
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.