wheybags
wheybags

Reputation: 657

C regex get index of match

I'm trying to use regexes by using regcomp() and regexec() from regex.h, and was wondering if there was any way to get the index of the match if there is one found?

Like if my regex is just "m", and I search "home", I would want 2.

Upvotes: 2

Views: 502

Answers (1)

Michael Goldshteyn
Michael Goldshteyn

Reputation: 74420

Take a look at the pmatch and nmatch arguments to regexec(). From the man page:

regexec() is used to match a null-terminated string against the precompiled pattern buffer, preg. nmatch and pmatch are used to provide information regarding the location of any matches. eflags may be the bitwise-or of one or both of REG_NOTBOL and REG_NOTEOL which cause changes in matching behaviour described below.

Upvotes: 2

Related Questions