免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
论坛 程序设计 Perl @+ @-
最近访问板块 发新帖
查看: 2094 | 回复: 5
打印 上一主题 下一主题

@+ @- [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-28 11:05 |只看该作者 |倒序浏览
@+   @-
有没人知道这两个是什么意思啊。
精通perl那上面有讲了点。
但没看懂。。

论坛徽章:
0
2 [报告]
发表于 2008-08-28 11:07 |只看该作者
好像一个是放$1...$2这些
一个好像是放$&
不知道哪个是对应哪个
那放$&的这个
里面$(-或+)[0....$#+]这里面是什么?

论坛徽章:
0
3 [报告]
发表于 2008-08-28 11:19 |只看该作者
被我找到了。
$-[0]和$+[0] 代表当前匹配的正则表达式在被匹配的字符串中的起始和终止的位置 。

试了下。终于给我明白了。。。

[ 本帖最后由 9119111 于 2008-8-28 11:26 编辑 ]

论坛徽章:
0
4 [报告]
发表于 2008-08-28 11:59 |只看该作者
http://perldoc.perl.org/perlvar.html

# @LAST_MATCH_START
# @-

$-[0] is the offset of the start of the last successful match. $-[n] is the offset of the start of the substring matched by n-th subpattern, or undef if the subpattern did not match.

Thus after a match against $_, $& coincides with substr $_, $-[0], $+[0] - $-[0] . Similarly, $n coincides with substr $_, $-[n], $+[n] - $-[n] if $-[n] is defined, and $+ coincides with substr $_, $-[$#-], $+[$#-] - $-[$#-] . One can use $#- to find the last matched subgroup in the last successful match. Contrast with $#+ , the number of subgroups in the regular expression. Compare with @+ .

This array holds the offsets of the beginnings of the last successful submatches in the currently active dynamic scope. $-[0] is the offset into the string of the beginning of the entire match. The nth element of this array holds the offset of the nth submatch, so $-[1] is the offset where $1 begins, $-[2] the offset where $2 begins, and so on.

After a match against some variable $var:

    * $` is the same as substr($var, 0, $-[0])
    * $& is the same as substr($var, $-[0], $+[0] - $-[0])
    * $' is the same as substr($var, $+[0])
    * $1 is the same as substr($var, $-[1], $+[1] - $-[1])
    * $2 is the same as substr($var, $-[2], $+[2] - $-[2])
    * $3 is the same as substr($var, $-[3], $+[3] - $-[3])

论坛徽章:
0
5 [报告]
发表于 2008-08-29 08:26 |只看该作者

论坛徽章:
0
6 [报告]
发表于 2008-08-29 13:15 |只看该作者
这些东西用到再查。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP