douchi0471 2014-04-01 08:49
浏览 27
已采纳

这个preg_match语法与“。+?”匹配的是什么

I know perl style regular expresions fairly well, but today I found one that I do not understand:

preg_match('/^On.+?wrote:.+?$/i',$line); //reduced example

What does the .+? mean? I undarstand the .+ alone, I understand .? alone. But .+?? It seems a bug to me.

The line should match popular citation prefixes in the email body and it is much more complicated along with look behinds, but this is the only part i can't understand, and still the regexp seems to work correclty.

  • 写回答

3条回答 默认 最新

  • dongqiao1158 2014-04-01 08:52
    关注

    + means one or more and is greedy. +? means the same, it just is not greedy like usual regex are.

    Edit: I wanted to explain it a little further, but the comment of deceze already explains enough.^^

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退