dongyaofu0599 2011-08-18 04:09
浏览 48
已采纳

PHP Regex匹配以大写字母开头的那些

It sounds pretty simple but I cant figure this out, please help me out.

So... I have file with following data:

Name: Santi
Surname: Dore
Name: Rob
Surname: Doe
and so on..

I need to match only the whole part that starts with "Name:" ... NOT "Surname:" ...

Here is what I am using right now to match it:

/Name(:)(.*)/i

It will match both but I need just Name: ...

Please dont suggest any other way of finding, just please help me out with regex to work the way I described.

  • 写回答

3条回答 默认 最新

  • douyouyi8878 2011-08-18 04:11
    关注

    Leave off the i modifier, which makes the regex case-insensitive.

    And/or, add some word boundaries:

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

报告相同问题?

悬赏问题

  • ¥15 从Freecad中宏下载的DesignSPHysics,出现如下问题是什么原因导致的(语言-python)
  • ¥30 notepad++ 自定义代码补全提示
  • ¥15 MATLAB有限差分法解一维边值问题
  • ¥200 内网渗透测试 横向渗透 Windows漏洞 Windows权限维持
  • ¥15 数据结构图的相关代码实现
  • ¥15 python中aiohttp.client_exceptions.ContentTypeError
  • ¥30 DeepLung肺结节检测生成最大froc值对应的epoch报错
  • ¥15 信号发生器如何将频率调大,步尽值改成10
  • ¥15 keil 5 编程智能家具,风扇台灯开关,人体感应等
  • ¥100 找一名渗透方面的专家