POSIX regex

1 отговора 96 прегледа
#1

POSIX regex

Zdrasti na vsichki!

Da popitam, moje li niakoy da mi pomogne demek da mi napishe regex, koyto
da matchva IP adres?
Stava vupros za GNU C regex a ne za t.nar. regex na Perl.
Ako niakoy go e pravil de.
10x

Отговор
в отговор на peyo #2

Re: POSIX regex

#include <stdio.h>
#include <regex.h>

int main (void)
{
regex_t regip;
regmatch_t bytes[5];

if (!regcomp(&regip, "([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,
{//successful regex pattern compilation
if (!regexec(&regip, str, 5, bytes,0))
{//sucessful match of ip address
/* bytes[0] -> the whole ip address i.e. the whole regex
bytes[n]; 1>=n<=4 - the corresponding octet(part) from the decimal-dotted notation i.e. the regex submatches
*/
}
}
}

Отговор