James B James B - 5 months ago 7x
Perl Question

Remove micro sign unicode character

I'm trying to strip the micro (μ) unicode character from a string using perl regexs. Take the string

$string = "This is a micro μ and some more μμμ";

Using a brute force approach to remove all 'more specialised' unicode characters does the job, i.e.,

$string =~ s/[\x80-\xFF]+//g;

But the following that singles out the micro character does not work for me

$string =~ s/\xB5+//g;

Pretty sure 00B5 is the unicode for the micro sign. Any ideas where I'm going wrong?


This may not be the micro sign, check out the similar Greek small letter mu, as tobyink has suggested in his comment.

use strict;
use warnings;
use utf8;
my $string = "This is a micro μ and some more μμμ";
$string =~ s/\x{03BC}//g;
print $string;

Output: This is a micro and some more