c# - Regular expressions in C -


i trying regular expressions matching in c , right working on ip addresses match.

in c# go pattern :

//doesn't matter if not correct ip, or 4 groups of 3 digits separated string string pattern = @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"; 

in c, modified pattern, doesn't seem give results, suppose there way of representing regular expressions use regcomp , regexec.

what correct regular expression in c match ip address? reference tutorial nice too.

edit: excerpt of code

.. #include <regex.h> ..  int main(int argc, char *argv[]){         regex_t regex;         int reti;          char* pattern = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}";         reti = regcomp(&regex, pattern, 0);         if( reti ){ fprintf(stderr, "could not compile regex\n"); exit(1); }          reti = regexec(&regex, "21.21.12.12", 0, null, 0);         if( !reti ){                 puts("match");         }         else                 puts("no match");          return 0; } 

edit 2: solution use posix bracket expressions as explained here

instead of \d have use [0-9] or maybe [:digit:] , { } syntax should supported rest can ketp, far can remember. if not, consider using pcre instead of "default" regex (in case, don't need change in c#)


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -