1

The $line contains unicode comma.

use strict;
use utf8;

my $line = "Spy,qqq,Iwm";

$line =~ s/[^a-zA-Z u002cu002e]+//g;
print $line."\n";

When i run it, i get $ perl 1.pl

SpyqqqIwm

Any suggestions ?

3
  • u002c should be \x{002c} or \x2c or ,
    – ikegami
    Apr 20, 2019 at 20:21
  • u002e should be \x{002e} or \x2e or .
    – ikegami
    Apr 20, 2019 at 20:21
  • Note that to print unicode characters properly you will either need to encode it to your terminal's encoding (most likely UTF-8) or set an encoding layer on STDOUT (use open ':std', ':encoding(UTF-8)' or -CS on the commandline).
    – Grinnz
    Apr 22, 2019 at 16:29

1 Answer 1

5

The character in question is U+FF0C FULLWIDTH COMMA

You can use it literally.

s/[^a-zA-Z ,,.]+//g

Alternatively, you can use one of the following in double-quoted and regex literals:

\N{U+FF0C}
\N{FULLWIDTH COMMA}
\x{FF0C}

For example,

s/[^a-zA-Z ,\N{U+FF0C}.]+//g
1
  • Not easy, for period, 4 of them, U+3002 。 e3 80 82 IDEO­GRAPHIC FULL STOP IDEOGRAPHIC PERIOD U+FE52 ﹒ ef b9 92 SMALL FULL STOP SMALL PERIOD U+FF0E . ef bc 8e FULLWIDTH FULL STOP FULLWIDTH PERIOD U+FF61 。 ef bd a1 HALFWIDTH IDEO­GRAPHIC FULL STOP HALFWIDTH IDEOGRAPHIC PERIOD Apr 20, 2019 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.