Parsing URL with regex: how it is done in apache
http://www.divms.uiowa.edu/~luke/xls/projects/regexp/regexp.html#NWcite-welch97:_pract_progr_tcl_tk
http://www.divms.uiowa.edu/~luke/xls/projects/regexp/regexp.html
Unix Programming Examples: Parsing Command Line - Regular expressions
http://mij.oltrelinux.com/devel/unixprg/#regex_notes
Regexex / regcomp
http://www.opengroup.org/onlinepubs/000095399/functions/regcomp.html
Fnmatch:
http://docs.hp.com/en/36430-90007/ch04s20.html
C++ string parse:
http://www.cprogramming.com/faq/cgi-bin/smartfaq.cgi?answer=1057105750&id=1044780608
#include
#include
#include
#include
#include
/* max error message length */
#define MAX_ERR_LENGTH 80
bool match( char * pattern, char * string );bool match( char * pattern, char * string ){
regex_t myre;
int err;
char err_msg[MAX_ERR_LENGTH];
/* compiles the RE. If this step fails, reveals what's wrong with the RE */
if ( (err = regcomp(&myre, pattern, REG_EXTENDED)) != 0 ) {
regerror(err, &myre, err_msg, MAX_ERR_LENGTH);
printf("Error analyzing regular expression '%s': %s - %s:%d\n", pattern, err_msg, __FILE__,__LINE__);
regfree(&myre);
return false;
}
if ( (err = regexec(&myre, string, 0, NULL, 0)) == 0 ) {
regfree(&myre);
return true;
}
if ( err != REG_NOMATCH ) {
/* this is when errors have been encountered */
regerror(err, &myre, err_msg, MAX_ERR_LENGTH);
printf("Error analyzing regular expression '%s' over '%s': %s - %s:%d\n", pattern, string, err_msg, __FILE__,__LINE__);
}
regfree(&myre);
return false;
}//match
regex_t re;
int error;
char *buffer="gsiftp://alo:90/lls/lsld/l";
regmatch_t pm[8];
(void) regcomp (&re, "^(([^:]+)://)?([^:/]+)(:([0-9]+))?(/.*)", REG_EXTENDED);
error = regexec (&re, &buffer[0], 6, &pm[0], 0);
printf("%d %d\n",pm[3].rm_so, pm[3].rm_eo);
}
GNU C Library Pattern Matching
http://www.gnu.org/software/libc/manual/html_node/Pattern-Matching.html#Pattern-Matching
GNU C Library Wildcard Matching
http://www.gnu.org/software/libc/manual/html_node/Wildcard-Matching.html#Wildcard-Matching
No comments:
Post a Comment