Difference between revisions of "Tip 15: GCC Regex Library"

From Vlsiwiki
Jump to: navigation, search
(Created page with 'The C Regex library is standard with GCC and uses POSIX style regular expressions. This is opposed to Perl style regular expressions which are more common among scripting languag…')
 
Line 5: Line 5:
 
To include regex in C (or C++) you must include:
 
To include regex in C (or C++) you must include:
  
#include <sys/types.h>
+
#include <sys/types.h>
#include <regex.h>
+
#include <regex.h>
  
 
There are 4 available command:
 
There are 4 available command:
  
int    regcomp(regex_t *, const char *, int);
+
int    regcomp(regex_t *, const char *, int);
int    regexec(const regex_t *, const char *, size_t, regmatch_t[], int);
+
int    regexec(const regex_t *, const char *, size_t, regmatch_t[], int);
size_t regerror(int, const regex_t *, char *, size_t);
+
size_t regerror(int, const regex_t *, char *, size_t);
void  regfree(regex_t *);
+
void  regfree(regex_t *);
  
 
Beyond that, read the man page [http://pubs.opengroup.org/onlinepubs/007908799/xsh/regex.h.html]
 
Beyond that, read the man page [http://pubs.opengroup.org/onlinepubs/007908799/xsh/regex.h.html]

Revision as of 00:50, 9 March 2011

The C Regex library is standard with GCC and uses POSIX style regular expressions. This is opposed to Perl style regular expressions which are more common among scripting languages.

To include regex in C (or C++) you must include:

#include <sys/types.h>
#include <regex.h>

There are 4 available command:

int    regcomp(regex_t *, const char *, int);
int    regexec(const regex_t *, const char *, size_t, regmatch_t[], int);
size_t regerror(int, const regex_t *, char *, size_t);
void   regfree(regex_t *);

Beyond that, read the man page [1]