POSIX regex
1 отговора
96 прегледа
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
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
Re: POSIX regex
#include <stdio.h>
#include <regex.h>
int main (void)
{
regex_t regip;
regmatch_t bytes[5];
if (!regcomp(®ip, "([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,
{//successful regex pattern compilation
if (!regexec(®ip, 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
*/
}
}
}
#include <regex.h>
int main (void)
{
regex_t regip;
regmatch_t bytes[5];
if (!regcomp(®ip, "([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,
{//successful regex pattern compilation
if (!regexec(®ip, 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
*/
}
}
}