Skip to content

Instantly share code, notes, and snippets.

@nikosvaggalis
Last active September 2, 2018 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikosvaggalis/e5ede10ffa9c4384245364c722f944b7 to your computer and use it in GitHub Desktop.
Save nikosvaggalis/e5ede10ffa9c4384245364c722f944b7 to your computer and use it in GitHub Desktop.
unicode to ascii one line Perl lexer
use utf8;
# “ Unicode Character 'LEFT DOUBLE QUOTATION MARK' (U+201C) decimal 8220
# ” Unicode Character 'RIGHT DOUBLE QUOTATION MARK' (U+201D) decimal 8221
my $string="aaa“bbb”ccc";
%dispatch=(8220=>'X',8221=>'Y');
my $string1=$string=~ s/(.)(?{ if (ord $1 >127 ){$dispatch{ord($1)}} else {$1} })/$^R/gr;
print $string1;
#prints: aaaXbbbYccc
#Full article with example at
#https://www.i-programmer.info/programming/perl/9295-advanced-perl-regular-expressions-extended-constructs.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment