Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: String match in Chinese character

by pryrt (Priest)
on Mar 11, 2018 at 23:57 UTC ( #1210696=note: print w/replies, xml ) Need Help??


in reply to Re^2: String match in Chinese character
in thread String match in Chinese character

then escape the unicode in the regex:

use warnings;
use strict;
use utf8;
my $string = '看【厂家直销 儿童加绒加厚打底裤 中小童冬季】Ib';

binmode STDOUT, ':encoding(UTF-8)';
while ($string =~ /\x{3010}(.*?)\x{3011}/g) {
    print "Match: $string\n";
}

(I left the use utf8 so that I could easily include the same string that choroba did. However you get the string is fine)

Replies are listed 'Best First'.
Re^4: String match in Chinese character
by 1nickt (Monsignor) on Mar 12, 2018 at 01:42 UTC

    Or use the name of the character if you don't have the codes on the tip of your tongue:

    use warnings;
    use strict;
    use utf8;
    use charnames ':full';
    
    my $string = '看【厂家直销 儿童加绒加厚打底裤 中小童冬季】Ib';
    
    binmode STDOUT, ':encoding(UTF-8)';
    print "Match: $string\n" while $string =~ /
        \N{LEFT BLACK LENTICULAR BRACKET} (.*?) \N{RIGHT BLACK LENTICULAR BRACKET}
    /gx;
    


    The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1210696]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-04-20 22:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?