How do you capture a group with regex?

前端 未结 2 967
臣服心动
臣服心动 2021-02-01 16:47

I\'m trying to extract a string from another using regex. I\'m using the POSIX regex functions (regcomp, regexec ...), and I fail at capturing a group ...

F

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 17:22

    The 0th element of the pmatch array of regmatch_t structs will contain the boundaries of the whole string matched, as you have noticed. In your example, you are interested in the regmatch_t at index 1, not at index 0, in order to get information about the string matches by the subexpression.

    If you need more help, try editing your question to include an actual small code sample so that people can more easily spot the problem.

提交回复
热议问题