Last active
September 2, 2018 14:25
-
-
Save nikosvaggalis/e5ede10ffa9c4384245364c722f944b7 to your computer and use it in GitHub Desktop.
unicode to ascii one line Perl lexer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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