免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3468 | 回复: 3
打印 上一主题 下一主题

linux 正则表达式 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-03-15 12:44 |只看该作者 |倒序浏览
求解一下:
      ^.* 这个是代表以任意多个字符开头,那么^(.*?)这个代表匹配的是什么呢??
刚刚接触正则,不太懂...

论坛徽章:
307
程序设计版块每周发帖之星
日期:2016-04-08 00:41:33操作系统版块每日发帖之星
日期:2015-09-02 06:20:00每日论坛发贴之星
日期:2015-09-02 06:20:00程序设计版块每日发帖之星
日期:2015-09-04 06:20:00每日论坛发贴之星
日期:2015-09-04 06:20:00每周论坛发贴之星
日期:2015-09-06 22:22:00程序设计版块每日发帖之星
日期:2015-09-09 06:20:00程序设计版块每日发帖之星
日期:2015-09-19 06:20:00程序设计版块每日发帖之星
日期:2015-09-20 06:20:00每日论坛发贴之星
日期:2015-09-20 06:20:00程序设计版块每日发帖之星
日期:2015-09-22 06:20:00程序设计版块每日发帖之星
日期:2015-09-24 06:20:00
2 [报告]
发表于 2016-03-15 14:40 |只看该作者
应该为空吧.

论坛徽章:
6
15-16赛季CBA联赛之新疆
日期:2016-03-22 22:34:5915-16赛季CBA联赛之山东
日期:2016-04-11 09:08:41程序设计版块每日发帖之星
日期:2016-06-28 06:20:00程序设计版块每日发帖之星
日期:2016-07-19 06:20:00每日论坛发贴之星
日期:2016-07-19 06:20:0015-16赛季CBA联赛之青岛
日期:2016-07-20 22:44:17
3 [报告]
发表于 2016-03-15 23:59 |只看该作者
猜不出来的时候就试试:

$> perl -e '$_='abcd'; print "Matched: -->$1<--" if (/^(.*?)/);'
Matched: --><--

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
4 [报告]
发表于 2016-03-16 08:24 |只看该作者
回复 1# lzj24

Greedy issue


$ perldoc perlre
NAME
    perlre - Perl regular expressions

    ...

    By default, a quantified subpattern is "greedy", that is, it will match as
    many times as possible (given a particular starting location) while still
    allowing the rest of the pattern to match. If you want it to match the
    minimum number of times possible, follow the quantifier with a "?". Note
    that the meanings don't change, just the "greediness":

        *?        Match 0 or more times, not greedily
        +?        Match 1 or more times, not greedily
        ??        Match 0 or 1 time, not greedily
        {n}?      Match exactly n times, not greedily (redundant)
        {n,}?     Match at least n times, not greedily
        {n,m}?    Match at least n but not more than m times, not greedily


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP