Programming Wiki: [[Regex Regular Expression]] Examples

Programming Wiki : RegexExamples

WikiHomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Most recent edit on 2007-10-14 14:49:34 by MarkEdgar [edit description]

Additions:
Here are two simple grep implementations in C, one for the POSIX API, and one using PCRE.

Deletions:
Here are two simple grep implementations. These programs are unfinished examples and have bugs.



Edited on 2007-07-12 00:10:20 by ScottRippee

Additions:

Regular Expression Examples


Here are two simple grep implementations. These programs are unfinished examples and have bugs.

POSIX <regex.h> C program -- regrep.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <regex.h>

char enter_reverse_mode[] = "\33[7m";
char exit_reverse_mode[] = "\33[0m";

int main(int argc, char **argv)
{
  const char *pattern;
  int ec;
  regex_t expr;
  regmatch_t rm;
  char buf[12];
  size_t offset, length;
  int flags;
  assert(argc == 2);
  pattern = argv[1];
  if ((ec = regcomp(&expr, pattern, 0)) != 0) {
    char str[256];
    regerror(ec, &expr, str, sizeof str);
    fprintf(stderr, "%s: %s\n", pattern, str);
    return EXIT_FAILURE;
  }
  flags = 0;
  while (fgets(buf, sizeof buf, stdin)) {
    /* Find the end of the buffer */
    length = strcspn(buf, "\n");
    /* Check for beginning and end of line. */
    if (flags & REG_NOTEOL) {
            /* If the last line read was a partial line, then we are
             * not at the beginning of the line. */

      flags |= REG_NOTBOL;
      if (buf[length] == '\n')
        flags &= ~REG_NOTEOL;
    }
    else if (buf[length] != '\n') {
      /* We've read a partial line. */
      flags = REG_NOTEOL;
    }
    else {
      /* We have a complete line. */
      flags = 0;
    }
    /* get rid of any newline character */
    buf[length] = '\0';
    /* start at beginning of the buffer */
    offset = 0;
    while (regexec(&expr, buf + offset, 1, &rm, flags) == 0) {
      assert(rm.rm_so >= 0);
      /* we're not smart enough to support empty matches. */
      assert(rm.rm_eo > rm.rm_so);
      /* print the portion which precedes the match, then the match */
      printf("%.*s%s%.*s%s",
        rm.rm_so, buf + offset,
        enter_reverse_mode,
        rm.rm_eo - rm.rm_so, buf + offset + rm.rm_so,
        exit_reverse_mode);
      /* start next match at the end of this one. */
      offset += rm.rm_eo;
      /* we're no longer at the beginning of the line */
      flags |= REG_NOTBOL;
    }
    /* print remainder of the line */
    printf("%s", buf + offset);
    /* print a newline if we're at the end of a line */
    if (!(flags & REG_NOTEOL))
      putchar('\n');
  }
  return EXIT_SUCCESS;
}


PCRE <pcre.h> C program -- pcregrep.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <pcre.h>

char enter_reverse_mode[] = "\33[7m";
char exit_reverse_mode[] = "\33[0m";

int main(int argc, char **argv)
{
  const char *pattern;
  const char *errstr;
  int erroffset;
  pcre *expr;
  char line[512];
  assert(argc == 2); /* XXX fixme */
  pattern = argv[1];
  if (!(expr = pcre_compile(pattern, 0, &errstr, &erroffset, 0))) {
    fprintf(stderr, "%s: %s\n", pattern, errstr);
    return EXIT_FAILURE;
  }
  while (fgets(line, sizeof line, stdin)) {
    size_t len = strcspn(line, "\n");
    int matches[2];
    int offset = 0;
    int flags = 0;
    line[len] = '\0';
    while (0 < pcre_exec(expr, 0, line, len, offset, flags, matches, 2)) {
      printf("%.*s%s%.*s%s",
        matches[0] - offset, line + offset,
        enter_reverse_mode,
        matches[1] - matches[0], line + matches[0],
        exit_reverse_mode);
      offset = matches[1];
      flags |= PCRE_NOTBOL;
    }
    printf("%s\n", line + offset);
  }
  return EXIT_SUCCESS;
}


Deletions:
tracfone ringtones flexeril online midi ringtones but ultram sony ericsson ringtones free wwe ringtones real ringtones nokia ringtones punk ringtones free funny ringtones free cool ringtones free funny ringtones cheap didrex paxil online lorazepam online mtv ringtones alprazolam online cheap pharmacy online free sony ringtones free free ringtones cheap vigrx free polyphonic ringtones free mp3 ringtones free polyphonic ringtones polyphonic ringtones order tramadol cheap adipex cheap ultracet cheap viagra buy diazepam zoloft online vigrx cheap lisinopril cheap pharmacy online cheap celexa sprint ringtones cheap clonazepam online levitra but sildenafil vicodin online xanax cheap valium pharmacy online online sildenafil online cheap wellbutrin cheap adipex vicodin online wwe ringtones alltel ringtones verizon ringtones free midi ringtones buy prozac but lipitor free sony ericsson ringtones sony ringtones cheap albuterol cheap viagra carisoprodol online free sony ericsson ringtones propecia online nexium lorazepam online cheap flexeril tracfone ringtones cheap clomid order paxil motorola ringtones zyban online free qwest ringtones free nextel ringtones clonazepam online music ringtones cheap tramadol soma online buy cyclobenzaprine tramadol online ativan online adipex online nexium online clonazepam online cheap hgh tenuate online zoloft midi ringtones cheap alprazolam ambien online sony ericsson ringtones cheap lisinopril free midi ringtones cheap carisoprodol free nokia ringtones free funny ringtones didrex online buy hgh didrex online free sony ringtones cheap ultram hgh online free ericsson ringtones fioricet cialis order flexeril cheap carisoprodol real ringtones hoodia online but ambien cheap lipitor free online pharmacy free free ringtones buy zanaflex cheap phentermine buy diethylpropion soma online free sprint ringtones cheap diazepam free sharp ringtones cheap hydrocodone adipex buy xanax clomid online free tracfone ringtones free sharp ringtones lisinopril wellbutrin online free kyocera ringtones motorola ringtones cheap phentermine zoloft online carisoprodol online buy alprazolam cheap diethylpropion free nokia ringtones cheap albuterol free funny ringtones valium online tramadol online online fioricet viagra online free samsung ringtones mtv ringtones order norco music ringtones ativan online tenuate online lipitor online free ericsson ringtones order soma cheap ambien order rivotril cialis buy tramadol free ericsson ringtones free mtv ringtones cheap propecia free jazz ringtones kyocera ringtones viagra online but norco free alltel ringtones buy zanaflex free motorola ringtones viagra online lortab online free music ringtones mp3 ringtones albuterol online clonazepam online ambien online order xenical free real ringtones nexium online wellbutrin sonyericsson ringtones celexa online cheap diazepam free nextel ringtones soma online free mp3 ringtones hoodia online free nextel ringtones vicodin online sagem ringtones free punk ringtones propecia online free mono ringtones polyphonic ringtones cheap levitra wwe ringtones cheap lorazepam samsung ringtones buy zanaflex norco online nexium online cheap ultram hoodia online hgh online free cool ringtones mono ringtones rivotril online buy meridia lorazepam mtv ringtones [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5



Edited on 2007-07-10 16:34:45 by Jx7Nsp

Additions:
tracfone ringtones flexeril online midi ringtones but ultram sony ericsson ringtones free wwe ringtones real ringtones nokia ringtones punk ringtones free funny ringtones free cool ringtones free funny ringtones cheap didrex paxil online lorazepam online mtv ringtones alprazolam online cheap pharmacy online free sony ringtones free free ringtones cheap vigrx free polyphonic ringtones free mp3 ringtones free polyphonic ringtones polyphonic ringtones order tramadol cheap adipex cheap ultracet cheap viagra buy diazepam zoloft online vigrx cheap lisinopril cheap pharmacy online cheap celexa sprint ringtones cheap clonazepam online levitra but sildenafil vicodin online xanax cheap valium pharmacy online online sildenafil online cheap wellbutrin cheap adipex vicodin online wwe ringtones alltel ringtones verizon ringtones free midi ringtones buy prozac but lipitor free sony ericsson ringtones sony ringtones cheap albuterol cheap viagra carisoprodol online free sony ericsson ringtones propecia online nexium lorazepam online cheap flexeril tracfone ringtones cheap clomid order paxil motorola ringtones zyban online free qwest ringtones free nextel ringtones clonazepam online music ringtones cheap tramadol soma online buy cyclobenzaprine tramadol online ativan online adipex online nexium online clonazepam online cheap hgh tenuate online zoloft midi ringtones cheap alprazolam ambien online sony ericsson ringtones cheap lisinopril free midi ringtones cheap carisoprodol free nokia ringtones free funny ringtones didrex online buy hgh didrex online free sony ringtones cheap ultram hgh online free ericsson ringtones fioricet cialis order flexeril cheap carisoprodol real ringtones hoodia online but ambien cheap lipitor free online pharmacy free free ringtones buy zanaflex cheap phentermine buy diethylpropion soma online free sprint ringtones cheap diazepam free sharp ringtones cheap hydrocodone adipex buy xanax clomid online free tracfone ringtones free sharp ringtones lisinopril wellbutrin online free kyocera ringtones motorola ringtones cheap phentermine zoloft online carisoprodol online buy alprazolam cheap diethylpropion free nokia ringtones cheap albuterol free funny ringtones valium online tramadol online online fioricet viagra online free samsung ringtones mtv ringtones order norco music ringtones ativan online tenuate online lipitor online free ericsson ringtones order soma cheap ambien order rivotril cialis buy tramadol free ericsson ringtones free mtv ringtones cheap propecia free jazz ringtones kyocera ringtones viagra online but norco free alltel ringtones buy zanaflex free motorola ringtones viagra online lortab online free music ringtones mp3 ringtones albuterol online clonazepam online ambien online order xenical free real ringtones nexium online wellbutrin sonyericsson ringtones celexa online cheap diazepam free nextel ringtones soma online free mp3 ringtones hoodia online free nextel ringtones vicodin online sagem ringtones free punk ringtones propecia online free mono ringtones polyphonic ringtones cheap levitra wwe ringtones cheap lorazepam samsung ringtones buy zanaflex norco online nexium online cheap ultram hoodia online hgh online free cool ringtones mono ringtones rivotril online buy meridia lorazepam mtv ringtones [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5

Deletions:
lorazepam mtv ringtones buy alprazolam cheap pharmacy online sony ringtones free free ringtones vigrx online polyphonic ringtones free mp3 ringtones free polyphonic ringtones polyphonic ringtones tramadol online cheap adipex but ultracet cheap viagra buy diazepam zoloft online cheap vigrx cheap lisinopril pharmacy online online celexa online free sprint ringtones clonazepam online levitra online but sildenafil cheap vicodin online xanax valium online pharmacy online online sildenafil online wellbutrin online order adipex order vicodin wwe ringtones alltel ringtones verizon ringtones midi ringtones buy prozac cheap lipitor free sony ericsson ringtones free sony ringtones albuterol online cheap viagra cheap carisoprodol free sony ericsson ringtones propecia online nexium online cheap lorazepam flexeril online tracfone ringtones clomid online cheap paxil motorola ringtones cheap zyban free qwest ringtones nextel ringtones clonazepam online free music ringtones cheap tramadol soma online cyclobenzaprine online tramadol online ativan online adipex online nexium online clonazepam online hgh online tenuate online zoloft online midi ringtones cheap alprazolam cheap ambien sony ericsson ringtones lisinopril online free midi ringtones cheap carisoprodol nokia ringtones funny ringtones cheap didrex buy hgh cheap didrex free sony ringtones ultram online buy hgh free ericsson ringtones fioricet online cialis order flexeril carisoprodol online free real ringtones hoodia online cheap ambien cheap lipitor online pharmacy free ringtones zanaflex online cheap phentermine diethylpropion online soma online sprint ringtones cheap diazepam sharp ringtones hydrocodone online online adipex xanax online cheap clomid tracfone ringtones free sharp ringtones lisinopril online wellbutrin online free kyocera ringtones free motorola ringtones phentermine online buy zoloft cheap carisoprodol buy alprazolam diethylpropion online nokia ringtones albuterol online funny ringtones valium online tramadol online fioricet online viagra online samsung ringtones mtv ringtones norco online free music ringtones buy ativan cheap tenuate buy lipitor ericsson ringtones soma online ambien online rivotril online cialis tramadol online free ericsson ringtones mtv ringtones cheap propecia free jazz ringtones free kyocera ringtones cheap viagra but norco free alltel ringtones zanaflex online motorola ringtones cheap viagra lortab online music ringtones mp3 ringtones albuterol online buy clonazepam ambien online xenical online real ringtones nexium online wellbutrin online sonyericsson ringtones celexa online cheap diazepam nextel ringtones cheap soma free mp3 ringtones hoodia free nextel ringtones vicodin online sagem ringtones punk ringtones propecia online free mono ringtones free polyphonic ringtones levitra online wwe ringtones cheap lorazepam samsung ringtones buy zanaflex norco buy nexium cheap ultram buy hoodia cheap hgh free cool ringtones free mono ringtones cheap rivotril buy meridia cheap cialis free jazz ringtones clomid ortho ativan online diazepam online cingular ringtones cheap valium hydrocodone online ativan free sagem ringtones but alprazolam rivotril online free cingular ringtones

Regular Expression Examples


Here are two simple grep implementations. These programs are unfinished examples and have bugs.

POSIX <regex.h> C program -- regrep.c
%%(c)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <regex.h>

char enter_reverse_mode[] = "\33[7m";
char exit_reverse_mode[] = "\33[0m";

int main(int argc, char argv)
{
const char *pattern;
int ec;
regex_t expr;
regmatch_t rm;
char buf[12];
size_t offset, length;
int flags;
assert(argc
2); pattern = argv[1];
if ((ec = regcomp(




Edited on 2007-07-10 16:33:19 by RlnXs2

Additions:
lorazepam mtv ringtones buy alprazolam cheap pharmacy online sony ringtones free free ringtones vigrx online polyphonic ringtones free mp3 ringtones free polyphonic ringtones polyphonic ringtones tramadol online cheap adipex but ultracet cheap viagra buy diazepam zoloft online cheap vigrx cheap lisinopril pharmacy online online celexa online free sprint ringtones clonazepam online levitra online but sildenafil cheap vicodin online xanax valium online pharmacy online online sildenafil online wellbutrin online order adipex order vicodin wwe ringtones alltel ringtones verizon ringtones midi ringtones buy prozac cheap lipitor free sony ericsson ringtones free sony ringtones albuterol online cheap viagra cheap carisoprodol free sony ericsson ringtones propecia online nexium online cheap lorazepam flexeril online tracfone ringtones clomid online cheap paxil motorola ringtones cheap zyban free qwest ringtones nextel ringtones clonazepam online free music ringtones cheap tramadol soma online cyclobenzaprine online tramadol online ativan online adipex online nexium online clonazepam online hgh online tenuate online zoloft online midi ringtones cheap alprazolam cheap ambien sony ericsson ringtones lisinopril online free midi ringtones cheap carisoprodol nokia ringtones funny ringtones cheap didrex buy hgh cheap didrex free sony ringtones ultram online buy hgh free ericsson ringtones fioricet online cialis order flexeril carisoprodol online free real ringtones hoodia online cheap ambien cheap lipitor online pharmacy free ringtones zanaflex online cheap phentermine diethylpropion online soma online sprint ringtones cheap diazepam sharp ringtones hydrocodone online online adipex xanax online cheap clomid tracfone ringtones free sharp ringtones lisinopril online wellbutrin online free kyocera ringtones free motorola ringtones phentermine online buy zoloft cheap carisoprodol buy alprazolam diethylpropion online nokia ringtones albuterol online funny ringtones valium online tramadol online fioricet online viagra online samsung ringtones mtv ringtones norco online free music ringtones buy ativan cheap tenuate buy lipitor ericsson ringtones soma online ambien online rivotril online cialis tramadol online free ericsson ringtones mtv ringtones cheap propecia free jazz ringtones free kyocera ringtones cheap viagra but norco free alltel ringtones zanaflex online motorola ringtones cheap viagra lortab online music ringtones mp3 ringtones albuterol online buy clonazepam ambien online xenical online real ringtones nexium online wellbutrin online sonyericsson ringtones celexa online cheap diazepam nextel ringtones cheap soma free mp3 ringtones hoodia free nextel ringtones vicodin online sagem ringtones punk ringtones propecia online free mono ringtones free polyphonic ringtones levitra online wwe ringtones cheap lorazepam samsung ringtones buy zanaflex norco buy nexium cheap ultram buy hoodia cheap hgh free cool ringtones free mono ringtones cheap rivotril buy meridia cheap cialis free jazz ringtones clomid ortho ativan online diazepam online cingular ringtones cheap valium hydrocodone online ativan free sagem ringtones but alprazolam rivotril online free cingular ringtones

Regular Expression Examples

if ((ec = regcomp(


Deletions:

Regular Expression Examples

if ((ec = regcomp(&expr, pattern, 0)) != 0) {
char str[256];
regerror(ec, &expr, str, sizeof str);
fprintf(stderr, "%s: %s\n", pattern, str);
return EXIT_FAILURE;
}
flags = 0;
while (fgets(buf, sizeof buf, stdin)) {
/* Find the end of the buffer */
length = strcspn(buf, "\n");
/* Check for beginning and end of line. */
if (flags & REG_NOTEOL) {
/* If the last line read was a partial line, then we are
* not at the beginning of the line. */
flags |= REG_NOTBOL;
if (buf[length]
'\n') flags &= ~REG_NOTEOL;
}
else if (buf[length] != '\n') {
/* We've read a partial line. */
flags = REG_NOTEOL;
}
else {
/* We have a complete line. */
flags = 0;
}
/* get rid of any newline character */
buf[length] = '\0';
/* start at beginning of the buffer */
offset = 0;
while (regexec(&expr, buf + offset, 1, &rm, flags)
0) { assert(rm.rm_so >= 0);
/* we're not smart enough to support empty matches. */
assert(rm.rm_eo > rm.rm_so);
/* print the portion which precedes the match, then the match */
printf("%.*s%s%.*s%s",
rm.rm_so, buf + offset,
enter_reverse_mode,
rm.rm_eo - rm.rm_so, buf + offset + rm.rm_so,
exit_reverse_mode);
/* start next match at the end of this one. */
offset += rm.rm_eo;
/* we're no longer at the beginning of the line */
flags |= REG_NOTBOL;
}
/* print remainder of the line */
printf("%s", buf + offset);
/* print a newline if we're at the end of a line */
if (!(flags & REG_NOTEOL))
putchar('\n');
}
return EXIT_SUCCESS;
}
== PCRE <pcre.h> C program -- pcregrep.c ==
#include <pcre.h>
  const char *errstr;
  int erroffset;
  pcre *expr;
  char line[512];
  assert(argc == 2); /* XXX fixme */
  if (!(expr = pcre_compile(pattern, 0, &errstr, &erroffset, 0))) {
	fprintf(stderr, "%s: %s\n", pattern, errstr);
	return EXIT_FAILURE;
  }
  while (fgets(line, sizeof line, stdin)) {
	size_t len = strcspn(line, "\n");
	int matches[2];
	int offset = 0;
	int flags = 0;
	line[len] = '\0';
	while (0 < pcre_exec(expr, 0, line, len, offset, flags, matches, 2)) {
	  printf("%.*s%s%.*s%s",
	    matches[0] - offset, line + offset,
	    enter_reverse_mode,
	    matches[1] - matches[0], line + matches[0],
	    exit_reverse_mode);
	  offset = matches[1];
	  flags |= PCRE_NOTBOL;
	}
	printf("%s\n", line + offset);
  }
  return EXIT_SUCCESS;
}




Edited on 2007-07-05 10:22:12 by MarkEdgar [revert spam]

Additions:

Regular Expression Examples


Here are two simple grep implementations. These programs are unfinished examples and have bugs.

POSIX <regex.h> C program -- regrep.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <regex.h>

char enter_reverse_mode[] = "\33[7m";
char exit_reverse_mode[] = "\33[0m";

int main(int argc, char **argv)
{
  const char *pattern;
  int ec;
  regex_t expr;
  regmatch_t rm;
  char buf[12];
  size_t offset, length;
  int flags;
  assert(argc == 2);
  pattern = argv[1];
  if ((ec = regcomp(&expr, pattern, 0)) != 0) {
    char str[256];
    regerror(ec, &expr, str, sizeof str);
    fprintf(stderr, "%s: %s\n", pattern, str);
    return EXIT_FAILURE;
  }
  flags = 0;
  while (fgets(buf, sizeof buf, stdin)) {
    /* Find the end of the buffer */
    length = strcspn(buf, "\n");
    /* Check for beginning and end of line. */
    if (flags & REG_NOTEOL) {
            /* If the last line read was a partial line, then we are
             * not at the beginning of the line. */

      flags |= REG_NOTBOL;
      if (buf[length] == '\n')
        flags &= ~REG_NOTEOL;
    }
    else if (buf[length] != '\n') {
      /* We've read a partial line. */
      flags = REG_NOTEOL;
    }
    else {
      /* We have a complete line. */
      flags = 0;
    }
    /* get rid of any newline character */
    buf[length] = '\0';
    /* start at beginning of the buffer */
    offset = 0;
    while (regexec(&expr, buf + offset, 1, &rm, flags) == 0) {
      assert(rm.rm_so >= 0);
      /* we're not smart enough to support empty matches. */
      assert(rm.rm_eo > rm.rm_so);
      /* print the portion which precedes the match, then the match */
      printf("%.*s%s%.*s%s",
        rm.rm_so, buf + offset,
        enter_reverse_mode,
        rm.rm_eo - rm.rm_so, buf + offset + rm.rm_so,
        exit_reverse_mode);
      /* start next match at the end of this one. */
      offset += rm.rm_eo;
      /* we're no longer at the beginning of the line */
      flags |= REG_NOTBOL;
    }
    /* print remainder of the line */
    printf("%s", buf + offset);
    /* print a newline if we're at the end of a line */
    if (!(flags & REG_NOTEOL))
      putchar('\n');
  }
  return EXIT_SUCCESS;
}


PCRE <pcre.h> C program -- pcregrep.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <pcre.h>

char enter_reverse_mode[] = "\33[7m";
char exit_reverse_mode[] = "\33[0m";

int main(int argc, char **argv)
{
  const char *pattern;
  const char *errstr;
  int erroffset;
  pcre *expr;
  char line[512];
  assert(argc == 2); /* XXX fixme */
  pattern = argv[1];
  if (!(expr = pcre_compile(pattern, 0, &errstr, &erroffset, 0))) {
    fprintf(stderr, "%s: %s\n", pattern, errstr);
    return EXIT_FAILURE;
  }
  while (fgets(line, sizeof line, stdin)) {
    size_t len = strcspn(line, "\n");
    int matches[2];
    int offset = 0;
    int flags = 0;
    line[len] = '\0';
    while (0 < pcre_exec(expr, 0, line, len, offset, flags, matches, 2)) {
      printf("%.*s%s%.*s%s",
        matches[0] - offset, line + offset,
        enter_reverse_mode,
        matches[1] - matches[0], line + matches[0],
        exit_reverse_mode);
      offset = matches[1];
      flags |= PCRE_NOTBOL;
    }
    printf("%s\n", line + offset);
  }
  return EXIT_SUCCESS;
}


Deletions:
[[http://people.msoe.edu/~millerni/forums.php?show=topic



Edited on 2007-07-04 14:12:09 by CssEgu

Additions:
[[http://people.msoe.edu/~millerni/forums.php?show=topic

Deletions:
diazepam online tramadol online cheap wellbutrin free jazz ringtones cheap rivotril mtv ringtones cheap lipitor celexa online cheap ativan nokia ringtones norco online motorola ringtones ultram ultram online norco mono ringtones celexa online buy didrex online pharmacy propecia online phentermine online viagra online vicodin online sildenafil cheap lisinopril free sharp ringtones levitra online funny ringtones hydrocodone online valium cool ringtones clonazepam online cyclobenzaprine online verizon ringtones buy hgh cheap ambien free sony ringtones cheap cialis free cingular ringtones cialis online cheap prozac free qwest ringtones cheap didrex free punk ringtones free jazz ringtones free ringtones but ultracet flexeril online free nokia ringtones ativan online viagra online free midi ringtones sony ericsson ringtones free real ringtones adipex online free funny ringtones free punk ringtones tenuate online meridia free kyocera ringtones free sprint ringtones meridia online tenuate online cheap clomid ambien online sonyericsson ringtones cheap clomid free music ringtones free ericsson ringtones levitra online wwe ringtones free kyocera ringtones cheap nexium mp3 ringtones hgh online xanax online sagem ringtones xenical online but alprazolam music ringtones buy zanaflex verizon ringtones nextel ringtones tracfone ringtones buy diethylpropion albuterol online tramadol online free samsung ringtones free mp3 ringtones free wwe ringtones soma online free sharp ringtones cheap lisinopril cheap paxil motorola ringtones free samsung ringtones online vigrx sildenafil online paxil online zanaflex online rivotril online cheap diethylpropion free sprint ringtones polyphonic ringtones sagem ringtones cheap nexium cingular ringtones cheap cyclobenzaprine cheap pharmacy online free alltel ringtones sonyericsson ringtones free sony ericsson ringtones cheap diazepam online vicodin buy lipitor vigrx online free mtv ringtones cheap soma buy lorazepam real ringtones cheap zyban buy albuterol free ericsson ringtones cheap lorazepam zoloft but adipex buy wellbutrin alltel ringtones free cool ringtones nextel ringtones online zoloft clonazepam online valium online cheap fioricet free midi ringtones cheap xanax polyphonic ringtones hoodia online cheap lortab order alprazolam hydrocodone online cheap lortab ultracet online free free ringtones mono ringtones cheap carisoprodol free sony ringtones cheap ortho free tracfone ringtones cheap phentermine cheap ortho cheap xenical cheap prozac carisoprodol online cheap propecia cheap flexeril free qwest ringtones buy fioricet cheap hoodia cheap zyban [[http://people.msoe.edu/~millerni/forums.php?show=topic



Edited on 2007-07-04 12:35:40 by GptH70

Additions:
diazepam online tramadol online cheap wellbutrin free jazz ringtones cheap rivotril mtv ringtones cheap lipitor celexa online cheap ativan nokia ringtones norco online motorola ringtones ultram ultram online norco mono ringtones celexa online buy didrex online pharmacy propecia online phentermine online viagra online vicodin online sildenafil cheap lisinopril free sharp ringtones levitra online funny ringtones hydrocodone online valium cool ringtones clonazepam online cyclobenzaprine online verizon ringtones buy hgh cheap ambien free sony ringtones cheap cialis free cingular ringtones cialis online cheap prozac free qwest ringtones cheap didrex free punk ringtones free jazz ringtones free ringtones but ultracet flexeril online free nokia ringtones ativan online viagra online free midi ringtones sony ericsson ringtones free real ringtones adipex online free funny ringtones free punk ringtones tenuate online meridia free kyocera ringtones free sprint ringtones meridia online tenuate online cheap clomid ambien online sonyericsson ringtones cheap clomid free music ringtones free ericsson ringtones levitra online wwe ringtones free kyocera ringtones cheap nexium mp3 ringtones hgh online xanax online sagem ringtones xenical online but alprazolam music ringtones buy zanaflex verizon ringtones nextel ringtones tracfone ringtones buy diethylpropion albuterol online tramadol online free samsung ringtones free mp3 ringtones free wwe ringtones soma online free sharp ringtones cheap lisinopril cheap paxil motorola ringtones free samsung ringtones online vigrx sildenafil online paxil online zanaflex online rivotril online cheap diethylpropion free sprint ringtones polyphonic ringtones sagem ringtones cheap nexium cingular ringtones cheap cyclobenzaprine cheap pharmacy online free alltel ringtones sonyericsson ringtones free sony ericsson ringtones cheap diazepam online vicodin buy lipitor vigrx online free mtv ringtones cheap soma buy lorazepam real ringtones cheap zyban buy albuterol free ericsson ringtones cheap lorazepam zoloft but adipex buy wellbutrin alltel ringtones free cool ringtones nextel ringtones online zoloft clonazepam online valium online cheap fioricet free midi ringtones cheap xanax polyphonic ringtones hoodia online cheap lortab order alprazolam hydrocodone online cheap lortab ultracet online free free ringtones mono ringtones cheap carisoprodol free sony ringtones cheap ortho free tracfone ringtones cheap phentermine cheap ortho cheap xenical cheap prozac carisoprodol online cheap propecia cheap flexeril free qwest ringtones buy fioricet cheap hoodia cheap zyban [[http://people.msoe.edu/~millerni/forums.php?show=topic

Deletions:
diazepam online cheap tramadol wellbutrin online free jazz ringtones rivotril online mtv ringtones lipitor online celexa online cheap ativan free nokia ringtones order norco free motorola ringtones cheap ultram ultram online norco online mono ringtones celexa online didrex online online pharmacy propecia online cheap phentermine viagra online vicodin online sildenafil cheap lisinopril sharp ringtones levitra online funny ringtones but hydrocodone online valium free cool ringtones cheap clonazepam buy cyclobenzaprine free verizon ringtones buy hgh cheap ambien sony ringtones cialis online cingular ringtones cheap cialis prozac online free qwest ringtones didrex online free punk ringtones free jazz ringtones free free ringtones but ultracet order flexeril nokia ringtones ativan online viagra online free midi ringtones sony ericsson ringtones free real ringtones adipex online free funny ringtones free punk ringtones tenuate online online meridia kyocera ringtones sprint ringtones online meridia order tenuate cheap clomid order ambien free sonyericsson ringtones clomid online music ringtones free ericsson ringtones levitra online free wwe ringtones free kyocera ringtones nexium online free mp3 ringtones cheap hgh cheap xanax sagem ringtones cheap xenical cheap alprazolam free music ringtones buy zanaflex verizon ringtones nextel ringtones free tracfone ringtones buy diethylpropion cheap albuterol tramadol online samsung ringtones free mp3 ringtones free wwe ringtones soma online sharp ringtones lisinopril online cheap paxil motorola ringtones free samsung ringtones online vigrx cheap sildenafil buy paxil zanaflex online cheap rivotril diethylpropion online sprint ringtones polyphonic ringtones sagem ringtones nexium online free cingular ringtones cheap cyclobenzaprine cheap pharmacy online alltel ringtones free sonyericsson ringtones sony ericsson ringtones diazepam online vicodin online buy lipitor vigrx online free mtv ringtones soma online buy lorazepam free real ringtones zyban online buy albuterol free ericsson ringtones lorazepam online zoloft but adipex wellbutrin online free alltel ringtones free cool ringtones nextel ringtones online zoloft cheap clonazepam cheap valium cheap fioricet midi ringtones cheap xanax polyphonic ringtones hoodia online lortab cheap alprazolam cheap hydrocodone cheap lortab ultracet online free free ringtones free mono ringtones cheap carisoprodol free sony ringtones cheap ortho tracfone ringtones but phentermine ortho online cheap xenical cheap prozac carisoprodol online propecia online but flexeril qwest ringtones buy fioricet cheap hoodia zyban online [[http://people.msoe.edu/~millerni/forums.php?show=topic



Edited on 2007-07-04 12:11:42 by Jx7Nsp

Additions:
diazepam online cheap tramadol wellbutrin online free jazz ringtones rivotril online mtv ringtones lipitor online celexa online cheap ativan free nokia ringtones order norco free motorola ringtones cheap ultram ultram online norco online mono ringtones celexa online didrex online online pharmacy propecia online cheap phentermine viagra online vicodin online sildenafil cheap lisinopril sharp ringtones levitra online funny ringtones but hydrocodone online valium free cool ringtones cheap clonazepam buy cyclobenzaprine free verizon ringtones buy hgh cheap ambien sony ringtones cialis online cingular ringtones cheap cialis prozac online free qwest ringtones didrex online free punk ringtones free jazz ringtones free free ringtones but ultracet order flexeril nokia ringtones ativan online viagra online free midi ringtones sony ericsson ringtones free real ringtones adipex online free funny ringtones free punk ringtones tenuate online online meridia kyocera ringtones sprint ringtones online meridia order tenuate cheap clomid order ambien free sonyericsson ringtones clomid online music ringtones free ericsson ringtones levitra online free wwe ringtones free kyocera ringtones nexium online free mp3 ringtones cheap hgh cheap xanax sagem ringtones cheap xenical cheap alprazolam free music ringtones buy zanaflex verizon ringtones nextel ringtones free tracfone ringtones buy diethylpropion cheap albuterol tramadol online samsung ringtones free mp3 ringtones free wwe ringtones soma online sharp ringtones lisinopril online cheap paxil motorola ringtones free samsung ringtones online vigrx cheap sildenafil buy paxil zanaflex online cheap rivotril diethylpropion online sprint ringtones polyphonic ringtones sagem ringtones nexium online free cingular ringtones cheap cyclobenzaprine cheap pharmacy online alltel ringtones free sonyericsson ringtones sony ericsson ringtones diazepam online vicodin online buy lipitor vigrx online free mtv ringtones soma online buy lorazepam free real ringtones zyban online buy albuterol free ericsson ringtones lorazepam online zoloft but adipex wellbutrin online free alltel ringtones free cool ringtones nextel ringtones online zoloft cheap clonazepam cheap valium cheap fioricet midi ringtones cheap xanax polyphonic ringtones hoodia online lortab cheap alprazolam cheap hydrocodone cheap lortab ultracet online free free ringtones free mono ringtones cheap carisoprodol free sony ringtones cheap ortho tracfone ringtones but phentermine ortho online cheap xenical cheap prozac carisoprodol online propecia online but flexeril qwest ringtones buy fioricet cheap hoodia zyban online [[http://people.msoe.edu/~millerni/forums.php?show=topic

Deletions:
diazepam online order tramadol wellbutrin online jazz ringtones cheap rivotril mtv ringtones cheap lipitor celexa online cheap ativan free nokia ringtones cheap norco free motorola ringtones but ultram cheap ultram norco online mono ringtones cheap celexa buy didrex online pharmacy cheap propecia phentermine online buy viagra cheap vicodin but sildenafil lisinopril online free sharp ringtones online levitra free funny ringtones hydrocodone online valium cool ringtones cheap clonazepam cyclobenzaprine online free verizon ringtones hgh online ambien online sony ringtones cialis online free cingular ringtones cheap cialis prozac online qwest ringtones cheap didrex punk ringtones free jazz ringtones free ringtones but ultracet flexeril online free nokia ringtones ativan online viagra online midi ringtones free sony ericsson ringtones real ringtones cheap adipex funny ringtones free punk ringtones tenuate online online meridia free kyocera ringtones sprint ringtones online meridia tenuate online clomid online ambien online free sonyericsson ringtones clomid online free music ringtones free ericsson ringtones cheap levitra free wwe ringtones kyocera ringtones cheap nexium free mp3 ringtones cheap hgh cheap xanax free sagem ringtones xenical online cheap alprazolam music ringtones zanaflex online verizon ringtones nextel ringtones tracfone ringtones buy diethylpropion cheap albuterol buy tramadol samsung ringtones free mp3 ringtones wwe ringtones soma online sharp ringtones cheap lisinopril paxil online free motorola ringtones free samsung ringtones vigrx cheap sildenafil buy paxil zanaflex online rivotril online cheap diethylpropion sprint ringtones polyphonic ringtones free sagem ringtones cheap nexium free cingular ringtones cyclobenzaprine online cheap pharmacy online alltel ringtones sonyericsson ringtones sony ericsson ringtones diazepam online online vicodin buy lipitor vigrx online mtv ringtones cheap soma lorazepam online real ringtones cheap zyban buy albuterol free ericsson ringtones lorazepam online zoloft but adipex wellbutrin online alltel ringtones cool ringtones nextel ringtones zoloft clonazepam online valium online order fioricet midi ringtones cheap xanax polyphonic ringtones hoodia online but lortab order alprazolam hydrocodone online cheap lortab cheap ultracet free free ringtones free mono ringtones cheap carisoprodol sony ringtones ortho online tracfone ringtones cheap phentermine ortho online cheap xenical prozac online cheap carisoprodol cheap propecia cheap flexeril free qwest ringtones fioricet online hoodia online cheap zyban [[http://people.msoe.edu/~millerni/forums.php?show=topic



Edited on 2007-07-04 12:06:46 by RlnXs2

Additions:
diazepam online order tramadol wellbutrin online jazz ringtones cheap rivotril mtv ringtones cheap lipitor celexa online cheap ativan free nokia ringtones cheap norco free motorola ringtones but ultram cheap ultram norco online mono ringtones cheap celexa buy didrex online pharmacy cheap propecia phentermine online buy viagra cheap vicodin but sildenafil lisinopril online free sharp ringtones online levitra free funny ringtones hydrocodone online valium cool ringtones cheap clonazepam cyclobenzaprine online free verizon ringtones hgh online ambien online sony ringtones cialis online free cingular ringtones cheap cialis prozac online qwest ringtones cheap didrex punk ringtones free jazz ringtones free ringtones but ultracet flexeril online free nokia ringtones ativan online viagra online midi ringtones free sony ericsson ringtones real ringtones cheap adipex funny ringtones free punk ringtones tenuate online online meridia free kyocera ringtones sprint ringtones online meridia tenuate online clomid online ambien online free sonyericsson ringtones clomid online free music ringtones free ericsson ringtones cheap levitra free wwe ringtones kyocera ringtones cheap nexium free mp3 ringtones cheap hgh cheap xanax free sagem ringtones xenical online cheap alprazolam music ringtones zanaflex online verizon ringtones nextel ringtones tracfone ringtones buy diethylpropion cheap albuterol buy tramadol samsung ringtones free mp3 ringtones wwe ringtones soma online sharp ringtones cheap lisinopril paxil online free motorola ringtones free samsung ringtones vigrx cheap sildenafil buy paxil zanaflex online rivotril online cheap diethylpropion sprint ringtones polyphonic ringtones free sagem ringtones cheap nexium free cingular ringtones cyclobenzaprine online cheap pharmacy online alltel ringtones sonyericsson ringtones sony ericsson ringtones diazepam online online vicodin buy lipitor vigrx online mtv ringtones cheap soma lorazepam online real ringtones cheap zyban buy albuterol free ericsson ringtones lorazepam online zoloft but adipex wellbutrin online alltel ringtones cool ringtones nextel ringtones zoloft clonazepam online valium online order fioricet midi ringtones cheap xanax polyphonic ringtones hoodia online but lortab order alprazolam hydrocodone online cheap lortab cheap ultracet free free ringtones free mono ringtones cheap carisoprodol sony ringtones ortho online tracfone ringtones cheap phentermine ortho online cheap xenical prozac online cheap carisoprodol cheap propecia cheap flexeril free qwest ringtones fioricet online hoodia online cheap zyban [[http://people.msoe.edu/~millerni/forums.php?show=topic

Deletions:
online meridia free wwe ringtones cheap phentermine xanax online cheap hydrocodone zanaflex online free free ringtones buy didrex free real ringtones fioricet online buy diazepam cheap rivotril ativan online sonyericsson ringtones sagem ringtones verizon ringtones sharp ringtones ortho online wellbutrin online valium cheap nexium tracfone ringtones free sony ericsson ringtones free cool ringtones but zoloft free motorola ringtones free qwest ringtones samsung ringtones free nextel ringtones cheap celexa ericsson ringtones midi ringtones cheap tenuate levitra online cheap adipex punk ringtones propecia online cheap albuterol cheap alprazolam viagra online cheap tramadol free sony ringtones ambien online funny ringtones cheap hgh polyphonic ringtones cialis online free nokia ringtones cheap flexeril norco cheap ultracet cheap carisoprodol kyocera ringtones clonazepam online pharmacy online online cyclobenzaprine online cheap ultram cheap lisinopril cheap xenical zyban online mono ringtones lorazepam online sprint ringtones cheap lipitor order prozac free music ringtones hoodia online online vigrx cheap diethylpropion but lortab vicodin online mtv ringtones free alltel ringtones soma online jazz ringtones sildenafil online cheap paxil mp3 ringtones clomid online free cingular ringtones [[http://people.msoe.edu/~millerni/forums.php?show=topic



Edited on 2007-07-01 06:19:46 by RlnXs2

Additions:
online meridia free wwe ringtones cheap phentermine xanax online cheap hydrocodone zanaflex online free free ringtones buy didrex free real ringtones fioricet online buy diazepam cheap rivotril ativan online sonyericsson ringtones sagem ringtones verizon ringtones sharp ringtones ortho online wellbutrin online valium cheap nexium tracfone ringtones free sony ericsson ringtones free cool ringtones but zoloft free motorola ringtones free qwest ringtones samsung ringtones free nextel ringtones cheap celexa ericsson ringtones midi ringtones cheap tenuate levitra online cheap adipex punk ringtones propecia online cheap albuterol cheap alprazolam viagra online cheap tramadol free sony ringtones ambien online funny ringtones cheap hgh polyphonic ringtones cialis online free nokia ringtones cheap flexeril norco cheap ultracet cheap carisoprodol kyocera ringtones clonazepam online pharmacy online online cyclobenzaprine online cheap ultram cheap lisinopril cheap xenical zyban online mono ringtones lorazepam online sprint ringtones cheap lipitor order prozac free music ringtones hoodia online online vigrx cheap diethylpropion but lortab vicodin online mtv ringtones free alltel ringtones soma online jazz ringtones sildenafil online cheap paxil mp3 ringtones clomid online free cingular ringtones [[http://people.msoe.edu/~millerni/forums.php?show=topic

Deletions:
online meridia free wwe ringtones cheap phentermine cheap xanax hydrocodone online cheap zanaflex free ringtones didrex online real ringtones buy fioricet buy diazepam rivotril online cheap ativan sonyericsson ringtones sagem ringtones free verizon ringtones free sharp ringtones ortho online wellbutrin online online valium cheap nexium tracfone ringtones free sony ericsson ringtones free cool ringtones but zoloft motorola ringtones free qwest ringtones free samsung ringtones nextel ringtones celexa online ericsson ringtones midi ringtones cheap tenuate cheap levitra cheap adipex free punk ringtones propecia online albuterol online alprazolam online viagra online tramadol online free sony ringtones cheap ambien free funny ringtones hgh online free polyphonic ringtones cheap cialis nokia ringtones flexeril norco online ultracet online carisoprodol online free kyocera ringtones clonazepam online cheap pharmacy online cheap cyclobenzaprine ultram online lisinopril online xenical online zyban online free mono ringtones buy lorazepam sprint ringtones cheap lipitor prozac online free music ringtones hoodia online vigrx diethylpropion online cheap lortab cheap vicodin mtv ringtones free alltel ringtones cheap soma free jazz ringtones sildenafil online paxil online free mp3 ringtones cheap clomid cingular ringtones [[http://people.msoe.edu/~millerni/forums.php?show=topic



Edited on 2007-06-29 00:49:55 by Jx7Nsp

Additions:
online meridia free wwe ringtones cheap phentermine cheap xanax hydrocodone online cheap zanaflex free ringtones didrex online real ringtones buy fioricet buy diazepam rivotril online cheap ativan sonyericsson ringtones sagem ringtones free verizon ringtones free sharp ringtones ortho online wellbutrin online online valium cheap nexium tracfone ringtones free sony ericsson ringtones free cool ringtones but zoloft motorola ringtones free qwest ringtones free samsung ringtones nextel ringtones celexa online ericsson ringtones midi ringtones cheap tenuate cheap levitra cheap adipex free punk ringtones propecia online albuterol online alprazolam online viagra online tramadol online free sony ringtones cheap ambien free funny ringtones hgh online free polyphonic ringtones cheap cialis nokia ringtones flexeril norco online ultracet online carisoprodol online free kyocera ringtones clonazepam online cheap pharmacy online cheap cyclobenzaprine ultram online lisinopril online xenical online zyban online free mono ringtones buy lorazepam sprint ringtones cheap lipitor prozac online free music ringtones hoodia online vigrx diethylpropion online cheap lortab cheap vicodin mtv ringtones free alltel ringtones cheap soma free jazz ringtones sildenafil online paxil online free mp3 ringtones cheap clomid cingular ringtones [[http://people.msoe.edu/~millerni/forums.php?show=topic

Deletions:
online meridia wwe ringtones cheap phentermine xanax online hydrocodone online cheap zanaflex free free ringtones buy didrex real ringtones fioricet online diazepam online cheap rivotril ativan online free sonyericsson ringtones free sagem ringtones verizon ringtones sharp ringtones cheap ortho cheap wellbutrin valium cheap nexium tracfone ringtones free sony ericsson ringtones free cool ringtones but zoloft motorola ringtones free qwest ringtones samsung ringtones nextel ringtones cheap celexa ericsson ringtones midi ringtones tenuate online cheap levitra cheap adipex punk ringtones cheap propecia albuterol online alprazolam online buy viagra cheap tramadol free sony ringtones ambien online funny ringtones cheap hgh free polyphonic ringtones cheap cialis free nokia ringtones cheap flexeril norco online ultracet online carisoprodol online free kyocera ringtones clonazepam online pharmacy online online cyclobenzaprine online cheap ultram lisinopril online cheap xenical cheap zyban free mono ringtones lorazepam online free sprint ringtones lipitor online prozac online free music ringtones cheap hoodia online vigrx cheap diethylpropion lortab vicodin online free mtv ringtones alltel ringtones cheap soma jazz ringtones sildenafil online cheap paxil free mp3 ringtones cheap clomid free cingular ringtones

Regular Expression Examples


Here are two simple grep implementations. These programs are unfinished examples and have bugs.

POSIX <regex.h> C program -- regrep.c
%%(c)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <regex.h>

char enter_reverse_mode[] = "\33[7m";
char exit_reverse_mode[] = "\33[0m";

int main(int argc, char argv)
{
const char *pattern;
int ec;
regex_t expr;
regmatch_t rm;
char buf[12];
size_t offset, length;
int flags;
assert(argc
2); pattern = argv[1];
if ((ec = regcomp(




Edited on 2007-06-29 00:49:16 by RlnXs2

Additions:
online meridia wwe ringtones cheap phentermine xanax online hydrocodone online cheap zanaflex free free ringtones buy didrex real ringtones fioricet online diazepam online cheap rivotril ativan online free sonyericsson ringtones free sagem ringtones verizon ringtones sharp ringtones cheap ortho cheap wellbutrin valium cheap nexium tracfone ringtones free sony ericsson ringtones free cool ringtones but zoloft motorola ringtones free qwest ringtones samsung ringtones nextel ringtones cheap celexa ericsson ringtones midi ringtones tenuate online cheap levitra cheap adipex punk ringtones cheap propecia albuterol online alprazolam online buy viagra cheap tramadol free sony ringtones ambien online funny ringtones cheap hgh free polyphonic ringtones cheap cialis free nokia ringtones cheap flexeril norco online ultracet online carisoprodol online free kyocera ringtones clonazepam online pharmacy online online cyclobenzaprine online cheap ultram lisinopril online cheap xenical cheap zyban free mono ringtones lorazepam online free sprint ringtones lipitor online prozac online free music ringtones cheap hoodia online vigrx cheap diethylpropion lortab vicodin online free mtv ringtones alltel ringtones cheap soma jazz ringtones sildenafil online cheap paxil free mp3 ringtones cheap clomid free cingular ringtones

Regular Expression Examples



Deletions:

Regular Expression Examples





Edited on 2007-06-27 10:52:31 by RlnXs2

Additions:
if ((ec = regcomp(

Deletions:
if ((ec = regcomp(&expr, pattern, 0)) != 0) {
char str[256];
regerror(ec, &expr, str, sizeof str);
fprintf(stderr, "%s: %s\n", pattern, str);
return EXIT_FAILURE;
}
flags = 0;
while (fgets(buf, sizeof buf, stdin)) {
/* Find the end of the buffer */
length = strcspn(buf, "\n");
/* Check for beginning and end of line. */
if (flags & REG_NOTEOL) {
/* If the last line read was a partial line, then we are
* not at the beginning of the line. */
flags |= REG_NOTBOL;
if (buf[length]
'\n') flags &= ~REG_NOTEOL;
}
else if (buf[length] != '\n') {
/* We've read a partial line. */
flags = REG_NOTEOL;
}
else {
/* We have a complete line. */
flags = 0;
}
/* get rid of any newline character */
buf[length] = '\0';
/* start at beginning of the buffer */
offset = 0;
while (regexec(&expr, buf + offset, 1, &rm, flags)
0) { assert(rm.rm_so >= 0);
/* we're not smart enough to support empty matches. */
assert(rm.rm_eo > rm.rm_so);
/* print the portion which precedes the match, then the match */
printf("%.*s%s%.*s%s",
rm.rm_so, buf + offset,
enter_reverse_mode,
rm.rm_eo - rm.rm_so, buf + offset + rm.rm_so,
exit_reverse_mode);
/* start next match at the end of this one. */
offset += rm.rm_eo;
/* we're no longer at the beginning of the line */
flags |= REG_NOTBOL;
}
/* print remainder of the line */
printf("%s", buf + offset);
/* print a newline if we're at the end of a line */
if (!(flags & REG_NOTEOL))
putchar('\n');
}
return EXIT_SUCCESS;
}
== PCRE <pcre.h> C program -- pcregrep.c ==
#include <pcre.h>
  const char *errstr;
  int erroffset;
  pcre *expr;
  char line[512];
  assert(argc == 2); /* XXX fixme */
  if (!(expr = pcre_compile(pattern, 0, &errstr, &erroffset, 0))) {
	fprintf(stderr, "%s: %s\n", pattern, errstr);
	return EXIT_FAILURE;
  }
  while (fgets(line, sizeof line, stdin)) {
	size_t len = strcspn(line, "\n");
	int matches[2];
	int offset = 0;
	int flags = 0;
	line[len] = '\0';
	while (0 < pcre_exec(expr, 0, line, len, offset, flags, matches, 2)) {
	  printf("%.*s%s%.*s%s",
	    matches[0] - offset, line + offset,
	    enter_reverse_mode,
	    matches[1] - matches[0], line + matches[0],
	    exit_reverse_mode);
	  offset = matches[1];
	  flags |= PCRE_NOTBOL;
	}
	printf("%s\n", line + offset);
  }
  return EXIT_SUCCESS;
}




Edited on 2007-04-20 16:58:35 by MarkEdgar [revert probably spam]

Additions:
if ((ec = regcomp(&expr, pattern, 0)) != 0) {
char str[256];
regerror(ec, &expr, str, sizeof str);
fprintf(stderr, "%s: %s\n", pattern, str);
return EXIT_FAILURE;
}
flags = 0;
while (fgets(buf, sizeof buf, stdin)) {
/* Find the end of the buffer */
length = strcspn(buf, "\n");
/* Check for beginning and end of line. */
if (flags & REG_NOTEOL) {
/* If the last line read was a partial line, then we are
* not at the beginning of the line. */
flags |= REG_NOTBOL;
if (buf[length]
'\n') flags &= ~REG_NOTEOL;
}
else if (buf[length] != '\n') {
/* We've read a partial line. */
flags = REG_NOTEOL;
}
else {
/* We have a complete line. */
flags = 0;
}
/* get rid of any newline character */
buf[length] = '\0';
/* start at beginning of the buffer */
offset = 0;
while (regexec(&expr, buf + offset, 1, &rm, flags)
0) { assert(rm.rm_so >= 0);
/* we're not smart enough to support empty matches. */
assert(rm.rm_eo > rm.rm_so);
/* print the portion which precedes the match, then the match */
printf("%.*s%s%.*s%s",
rm.rm_so, buf + offset,
enter_reverse_mode,
rm.rm_eo - rm.rm_so, buf + offset + rm.rm_so,
exit_reverse_mode);
/* start next match at the end of this one. */
offset += rm.rm_eo;
/* we're no longer at the beginning of the line */
flags |= REG_NOTBOL;
}
/* print remainder of the line */
printf("%s", buf + offset);
/* print a newline if we're at the end of a line */
if (!(flags & REG_NOTEOL))
putchar('\n');
}
return EXIT_SUCCESS;
}
== PCRE <pcre.h> C program -- pcregrep.c ==
#include <pcre.h>
  const char *errstr;
  int erroffset;
  pcre *expr;
  char line[512];
  assert(argc == 2); /* XXX fixme */
  if (!(expr = pcre_compile(pattern, 0, &errstr, &erroffset, 0))) {
	fprintf(stderr, "%s: %s\n", pattern, errstr);
	return EXIT_FAILURE;
  }
  while (fgets(line, sizeof line, stdin)) {
	size_t len = strcspn(line, "\n");
	int matches[2];
	int offset = 0;
	int flags = 0;
	line[len] = '\0';
	while (0 < pcre_exec(expr, 0, line, len, offset, flags, matches, 2)) {
	  printf("%.*s%s%.*s%s",
	    matches[0] - offset, line + offset,
	    enter_reverse_mode,
	    matches[1] - matches[0], line + matches[0],
	    exit_reverse_mode);
	  offset = matches[1];
	  flags |= PCRE_NOTBOL;
	}
	printf("%s\n", line + offset);
  }
  return EXIT_SUCCESS;
}


Deletions:
if ((ec = regcomp(



Edited on 2007-04-19 11:31:52 by SoqQnx

Additions:
if ((ec = regcomp(

Deletions:
if ((ec = regcomp(&expr, pattern, 0)) != 0) {
char str[256];
regerror(ec, &expr, str, sizeof str);
fprintf(stderr, "%s: %s\n", pattern, str);
return EXIT_FAILURE;
}
flags = 0;
while (fgets(buf, sizeof buf, stdin)) {
/* Find the end of the buffer */
length = strcspn(buf, "\n");
/* Check for beginning and end of line. */
if (flags & REG_NOTEOL) {
/* If the last line read was a partial line, then we are
* not at the beginning of the line. */
flags |= REG_NOTBOL;
if (buf[length]
'\n') flags &= ~REG_NOTEOL;
}
else if (buf[length] != '\n') {
/* We've read a partial line. */
flags = REG_NOTEOL;
}
else {
/* We have a complete line. */
flags = 0;
}
/* get rid of any newline character */
buf[length] = '\0';
/* start at beginning of the buffer */
offset = 0;
while (regexec(&expr, buf + offset, 1, &rm, flags)
0) { assert(rm.rm_so >= 0);
/* we're not smart enough to support empty matches. */
assert(rm.rm_eo > rm.rm_so);
/* print the portion which precedes the match, then the match */
printf("%.*s%s%.*s%s",
rm.rm_so, buf + offset,
enter_reverse_mode,
rm.rm_eo - rm.rm_so, buf + offset + rm.rm_so,
exit_reverse_mode);
/* start next match at the end of this one. */
offset += rm.rm_eo;
/* we're no longer at the beginning of the line */
flags |= REG_NOTBOL;
}
/* print remainder of the line */
printf("%s", buf + offset);
/* print a newline if we're at the end of a line */
if (!(flags & REG_NOTEOL))
putchar('\n');
}
return EXIT_SUCCESS;
}
== PCRE <pcre.h> C program -- pcregrep.c ==
#include <pcre.h>
  const char *errstr;
  int erroffset;
  pcre *expr;
  char line[512];
  assert(argc == 2); /* XXX fixme */
  if (!(expr = pcre_compile(pattern, 0, &errstr, &erroffset, 0))) {
	fprintf(stderr, "%s: %s\n", pattern, errstr);
	return EXIT_FAILURE;
  }
  while (fgets(line, sizeof line, stdin)) {
	size_t len = strcspn(line, "\n");
	int matches[2];
	int offset = 0;
	int flags = 0;
	line[len] = '\0';
	while (0 < pcre_exec(expr, 0, line, len, offset, flags, matches, 2)) {
	  printf("%.*s%s%.*s%s",
	    matches[0] - offset, line + offset,
	    enter_reverse_mode,
	    matches[1] - matches[0], line + matches[0],
	    exit_reverse_mode);
	  offset = matches[1];
	  flags |= PCRE_NOTBOL;
	}
	printf("%s\n", line + offset);
  }
  return EXIT_SUCCESS;
}




Edited on 2006-01-05 18:09:29 by MarkEdgar

Additions:
Here are two simple grep implementations. These programs are unfinished examples and have bugs.

Deletions:
These programs are unfinished examples and have bugs.



Edited on 2005-12-04 11:08:59 by MarkEdgar [Added title which links back]

Additions:

Regular Expression Examples

These programs are unfinished examples and have bugs.


Deletions:
These programs are broken -- please fix them.



Edited on 2005-12-02 08:52:26 by MarkEdgar [OK, not quite yet ready for prime time]

Additions:
These programs are broken -- please fix them.



Edited on 2005-12-01 20:31:46 by MarkEdgar [added POSIX regex version]

Additions:
POSIX <regex.h> C program -- regrep.c
#include <sys/types.h>
#include <regex.h>
char enter_reverse_mode[] = "\33[7m";
char exit_reverse_mode[] = "\33[0m";
int main(int argc, char argv)
const char *pattern;
int ec;
regex_t expr;
regmatch_t rm;
char buf[12];
size_t offset, length;
int flags;
assert(argc
2); pattern = argv[1];
if ((ec = regcomp(&expr, pattern, 0)) != 0) {
char str[256];
regerror(ec, &expr, str, sizeof str);
fprintf(stderr, "%s: %s\n", pattern, str);
return EXIT_FAILURE;
}
flags = 0;
while (fgets(buf, sizeof buf, stdin)) {
/* Find the end of the buffer */
length = strcspn(buf, "\n");
/* Check for beginning and end of line. */
if (flags & REG_NOTEOL) {
/* If the last line read was a partial line, then we are
* not at the beginning of the line. */
flags |= REG_NOTBOL;
if (buf[length]
'\n') flags &= ~REG_NOTEOL;
}
else if (buf[length] != '\n') {
/* We've read a partial line. */
flags = REG_NOTEOL;
}
else {
/* We have a complete line. */
flags = 0;
}
/* get rid of any newline character */
buf[length] = '\0';
/* start at beginning of the buffer */
offset = 0;
while (regexec(&expr, buf + offset, 1, &rm, flags)
0) { assert(rm.rm_so >= 0);
/* we're not smart enough to support empty matches. */
assert(rm.rm_eo > rm.rm_so);
/* print the portion which precedes the match, then the match */
printf("%.*s%s%.*s%s",
rm.rm_so, buf + offset,
enter_reverse_mode,
rm.rm_eo - rm.rm_so, buf + offset + rm.rm_so,
exit_reverse_mode);
/* start next match at the end of this one. */
offset += rm.rm_eo;
/* we're no longer at the beginning of the line */
flags |= REG_NOTBOL;
}
/* print remainder of the line */
printf("%s", buf + offset);
/* print a newline if we're at the end of a line */
if (!(flags & REG_NOTEOL))
putchar('\n');
}
return EXIT_SUCCESS;
PCRE <pcre.h> C program -- pcregrep.c
char enter_reverse_mode[] = "\33[7m";
char exit_reverse_mode[] = "\33[0m";
int main(int argc, char
argv)
const char *pattern;
const char *errstr;
int erroffset;
pcre *expr;
char line[512];
assert(argc
2); /* XXX fixme */ pattern = argv[1];
if (!(expr = pcre_compile(pattern, 0, &errstr, &erroffset, 0))) {
fprintf(stderr, "%s: %s\n", pattern, errstr);
return EXIT_FAILURE;
}
while (fgets(line, sizeof line, stdin)) {
size_t len = strcspn(line, "\n");
int matches[2];
int offset = 0;
int flags = 0;
line[len] = '\0';
while (0 < pcre_exec(expr, 0, line, len, offset, flags, matches, 2)) {
printf("%.*s%s%.*s%s",
matches[0] - offset, line + offset,
enter_reverse_mode,
matches[1] - matches[0], line + matches[0],
exit_reverse_mode);
offset = matches[1];
flags |= PCRE_NOTBOL;
}
printf("%s\n", line + offset);
}
return EXIT_SUCCESS;

Deletions:
PCRE C program -- pcregrep.c
#define NELEMOF(array) (sizeof array/sizeof*array)
char rev[][10] = {"\33[7m","\33[1m"};
char sgr0[] = "\33[0m";
static pcre *
init(const char *pattern)
pcre *expr;
const char *errstr;
int erroffset;
if (!(expr = pcre_compile(pattern, 0, &errstr, &erroffset, 0))) {
fprintf(stderr, "%s: %s\n", pattern, errstr);
exit(EXIT_FAILURE);
}
return expr;
int
main(int argc, char argv)
pcre *expr;
char line[512];
int n = 0;
assert(argc
2); /* XXX fixme */ expr = init(argv[1]);
while (fgets(line, sizeof line, stdin)) {
size_t len = strcspn(line, "\n");
int matches[2];
int offset = 0;
int flags = 0;
line[len] = '\0';
while (0 < pcre_exec(expr, 0, line, len, offset, flags, matches, NELEMOF(matches))) {
printf("%.*s%s%.*s%s",
matches[0] - offset, line + offset,
rev[n % 2],
matches[1] - matches[0], line + matches[0],
sgr0);
offset = matches[1];
flags |= PCRE_NOTBOL;
}
printf("%s\n", line + offset);
}
return EXIT_SUCCESS;




Oldest known version of this page was edited on 2005-12-01 11:14:56 by MarkEdgar [Added example page]
Page view:
PCRE C program -- pcregrep.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <pcre.h>

#define NELEMOF(array) (sizeof array/sizeof*array)

char rev[][10] = {"\33[7m","\33[1m"};
char sgr0[] = "\33[0m";

static pcre *
init(const char *pattern)
{
        pcre *expr;
        const char *errstr;
        int erroffset;
        if (!(expr = pcre_compile(pattern, 0, &errstr, &erroffset, 0))) {
                fprintf(stderr, "%s: %s\n", pattern, errstr);
                exit(EXIT_FAILURE);
        }
        return expr;
}

int
main(int argc, char **argv)
{
        pcre *expr;
        char line[512];
        int n = 0;

        assert(argc == 2); /* XXX fixme */

        expr = init(argv[1]);

        while (fgets(line, sizeof line, stdin)) {
                size_t len = strcspn(line, "\n");
                int matches[2];
                int offset = 0;
                int flags = 0;
                line[len] = '\0';
                while (0 < pcre_exec(expr, 0, line, len, offset, flags, matches, NELEMOF(matches))) {
                        printf("%.*s%s%.*s%s",
                                matches[0] - offset, line + offset,
                                rev[++n % 2],
                                matches[1] - matches[0], line + matches[0],
                                sgr0);
                        offset = matches[1];
                        flags |= PCRE_NOTBOL;
                }
                printf("%s\n", line + offset);
        }
        return EXIT_SUCCESS;
}
Powered by Wikka Wakka Wiki 1.1.6.0
Page was generated in 0.2434 seconds