写了下面的脚本
#!/usr/bin/perl
#
# Program to do the obvious
#
local $/ = undef;
$lines = <FILE>;
$file = "mylog";
open(INFO,$file);# Open the file
$lines = <INFO>;# Read it into an array
close(INFO);# Close the file
print $lines;# Print the array
print "It matches 2\n" if $lines=~ m/\x{e5b7b2}/s;
创建了文件mylog,内容如下:
------------------分割线,非内容
记录文件已经开始工作
weiyuan carried them out at 2007年 08月 23日 星期四 21:53:31 CST
这一行是用cat命令添加的
------------------分割线,非内容
文件采用utf8编码。
查到“已”字的utf8编码是0xe5b7b2,想要用上面的脚本测试一下perl匹配正则表达式,但是输出是不匹配,请问为什么呢?
perl正则表达式匹配问题
-
- 帖子: 28
- 注册时间: 2007-05-06 10:56
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系:
代码: 全选
#!/usr/bin/perl
#
# Program to do the obvious
#
local $/ = undef;
$lines = <FILE>;
$file = "mylog";
open(INFO,$file);# Open the file
$lines = <INFO>;# Read it into an array
close(INFO);# Close the file
print $lines;# Print the array
print "It matches 2\n" if $lines=~ m/已/s;
^_^ ~~~
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
-
- 帖子: 28
- 注册时间: 2007-05-06 10:56
- nihui
- 帖子: 1746
- 注册时间: 2006-10-21 12:03
- 来自: Shanghai
- 联系:
[UTF8 "\x{.....}"]
貌似我还没看过文档.......
貌似我还没看过文档.......


代码: 全选
#!/usr/bin/perl
#
# Program to do the obvious
#
local $/ = undef;
$lines = <FILE>;
$file = "mylog";
open(INFO,$file);# Open the file
$lines = <INFO>;# Read it into an array
close(INFO);# Close the file
print $lines;# Print the array
print "It matches 2\n" if $lines=~ m/[UTF8 "\x{e5b7b2}"]/s;
-
- 帖子: 28
- 注册时间: 2007-05-06 10:56