Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: String match in Chinese character

by hankcoder (Scribe)
on Mar 11, 2018 at 22:43 UTC ( [id://1210692]=note: print w/replies, xml ) Need Help??


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

Thanks choroba for reply. The suggested method is as my very old way of coding style. However, I will encounter an issue with my editor whereby I must have the .pl file saved in UTF-8 encoded type in order to hard code it like while ($string =~ /【(.*?)】/g)

Furthermore, there are some other issue which I can't remember so I ditch such direct use of Chinese character in my codes.

  • Comment on Re^2: String match in Chinese character

Replies are listed 'Best First'.
Re^3: String match in Chinese character
by pryrt (Abbot) on Mar 11, 2018 at 23:57 UTC

    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)

      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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210692]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found