#include <stdio.h>
#include <string.h>
#include <pcre.h>
#define OVECCOUNT 30 /* should be a multiple of 3 */
int main() {
const char *error;
int erroffset;
pcre *re;
int rc;
int i;
char str[] = "regular expressions=very cool"; /* String to match */
int ovector[OVECCOUNT];
re = pcre_compile (
"([^=]*)=(.*)", /* the pattern */
0, /* default options */
&error, /* for error message */
&erroffset, /* for error offset */
0); /* use default character tables */
if (!re) {
printf("pcre_compile failed (offset: %d), %s\n", erroffset, error);
return -1;
}
rc = pcre_exec (
re, /* the compiled pattern */
0, /* no extra data - pattern was not studied */
str, /* the string to match */
strlen(str), /* the length of the string */
0, /* start at offset 0 in the subject */
0, /* default options */
ovector, /* output vector for substring information */
OVECCOUNT); /* number of elements in the output vector */
if (rc < 0) {
switch (rc) {
case PCRE_ERROR_NOMATCH:
printf("String didn't match");
break;
default:
printf("Error while matching: %d\n", rc);
break;
}
free(re);
return -1;
}
for (i = 0; i < rc; i++) {
printf("%2d: %.*s\n", i, ovector[2*i+1] - ovector[2*i], str + ovector[2*i]);
}
}
my $str = 'regular expressions=very cool';
$str =~ /([^=]*)=(.*)/;
my ($key, $value) = ($1, $2);
if( defined $key ) {
printf("%s = %s\n", $key, $value);
} else {
print "String didn't match\n";
}
HAHAHA:
LDX #$0F
STX $D021
DEX
BNE HAHAHA
~
I have spent the last 6 months learning C. And I am torn because i do love the simplicity of the language.
I love the fact that it's open source and that it runs on Linux/Unix. I love GDB and i love GCC.
I even love juggling pointers, it makes me feel powerful!
But when it comes to having to write / maintain low level functionality, it can be kind of daunting.
Some of you have been super helpful in your replies to some of my other posts about MySQL.
Anyone who's read them may have noticed that i'm more obsessed with coding than mudding. I guess its
just the way i am.
I love the idea of being able to easily change things in my MUD. And find that due to all the low level memory
issues, this can be not as fun as say, C# or JAVA or even Ruby due to the high level garbage collection.
Any Thoughts?