QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2017|回复: 2

正则表达式的模式

[复制链接]
发表于 2007-11-30 10:53:36 | 显示全部楼层 |阅读模式
我有一个字符串:"test"   "todo"
使用pattern      :^\".*?\"
希望找到字符串:"test"
  
可是找到的是整个字符串:"test"   "todo"
使用linux下面的regcomp 和regexec ,
请问 怎么构造pattern才能找到需要的字符串?
发表于 2008-2-19 09:35:45 | 显示全部楼层
你所给的两个字符串都是匹配的
这个应该可以了
:^\".*?t\"
回复

使用道具 举报

发表于 2008-2-25 15:49:54 | 显示全部楼层
你需要使用偏移量,man regexec里
BYTE OFFSETS el
       Unless  REG_NOSUB  was set for the compilation of the pattern buffer, it is possible to obtain substring match addressing information.
       pmatch must be dimensioned to have at least nmatch elements.  These are filled in by regexec() with substring  match  addresses.   Any
       unused structure elements will contain the value -1.

       The regmatch_t structure which is the type of pmatch is defined in regex.h.

              typedef struct
              {
                regoff_t rm_so;
                regoff_t rm_eo;
              } regmatch_t;

       Each  rm_so  element  that  is  not -1 indicates the start offset of the next largest substring match within the string.  The relative
       rm_eo element indicates the end offset of the match.

请查看
http://trac.lcuc.org.cn/public/t ... t/test_filesystem.c
中reg_replace如何替换HTML的,reg_replace工具在http://trac.lcuc.org.cn/public/t ... runk/util/regular.c
回复

使用道具 举报

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

本版积分规则

GMT+8, 2024-3-29 12:52 , Processed in 0.144304 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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