LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1174|回复: 6

模式匹配返回值问题

[复制链接]
发表于 2004-5-1 11:00:36 | 显示全部楼层 |阅读模式
一个文本文件有两行:
  1. f=eoiwhy  5fis55=3969 889=9252 kjfoiwef fai=eh wieufh
  2. foie foaw' fow  aewf fa6=fwo fgkf=dark 69kjdjkajh
复制代码

对此文本进行模式匹配搜索并赋值给列表变量。
  1. @array=/\w*=\w*/
复制代码
返回两个“ 1”

加括号匹配后:
  1. @array=/(\w*=\w*)/
复制代码
则返回匹配的字符串“ f=eoiwhy ”  "fa6=fwo"

能否讲解一下为什么两次返回值不一样:thank
发表于 2004-5-1 11:14:32 | 显示全部楼层
If the /g option is not used, m// in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, i.e., ($1, $2, $3...). (Note that here $1 etc. are also set, and that this differs from Perl 4's behavior.) When there are no parentheses in the pattern, the return value is the list (1) for success. With or without parentheses, an empty list is returned upon failure.
发表于 2004-5-1 11:21:00 | 显示全部楼层
另外请看骆驼书第177页。
两折买来的书要充分利用哦。
 楼主| 发表于 2004-5-1 11:42:28 | 显示全部楼层
谢谢 :thank
发表于 2004-5-1 11:51:51 | 显示全部楼层
  1. @array=/\b\w+=\w+\b/g;
复制代码

用边界也可~
发表于 2004-5-1 11:53:38 | 显示全部楼层
都不懂。。。谢谢大家指教!!
 楼主| 发表于 2004-5-1 17:25:56 | 显示全部楼层
骆驼书上说得详细,明白了,:thank  
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表