How do you match a regex to any string of characters but include some strings that must not match?
Say I have a block of C code and I want to wrap every function call with another function. The problem is that functions have the same form as operators such as main(), if(), etc. and
Basically, I need to match every \w*\(.*\) except main(), if() and the likes.
I don't even know what you're trying to even do but it sounds like you want to do some form of parsing instead of trying to wrangle convoluted shit language like PCRE to do something that is better done In sane parser generated languages like PEG, BNF, etc.
There are tons of PEG generators for a shitload of languages, peg.js, some ruby bullshit, etc.
If you have the time, use some parser generator, like said. For some popular ones like ANTLR you might even find grammar files for C etc. Also it might be worth pursuing to hack a pretty printer.
Austin Russell
You need to include a lot more information in your question. I'm assuming you're using a programming language. If that's the case, the easiest way (that those new to regex never think of, for some reason) is to just negate the match in the language.
Shitty pseudocode example: for (line in file) { if (!myLine.matches(functionCallRegex)) { continue; } if (line.matches(prohibitedStringsRegex)) { continue; } // Process the line }
Charles Hall
Thanks a lot user.
Thing is I just found a sweet way of profiling my code inspired in python decorators (the @ thing)
Now I just need to wrap all my functions in my "decorator" macro, but obviously have to skip the operators.
It sounds like the sort of thing a regex could do to the c file.
Nathaniel Garcia
Oops, change "myLine" to "line", but you should get the idea. Match what you *don't want* and then ignore the line if it matches.
Jaxon Wilson
>python spacing post disregarded
Sebastian Rivera
The fuck are you talking about? Isn't "python spacing" 4-space indentation? (Which that post doesn't use) I've never heard of someone complaining about it.
Brody Young
Paste some example code and I'll try to work my RegEx magic.
Alexander Nguyen
>posting xkcd ignore this guy, his regexes probably suck
Sebastian Martinez
They probably will, but if it can be done in RegEx I can do it. Probably.
Angel Turner
Never mind, spoken like a true regex user. Carry on, then
Leo Ramirez
int main(){ printf(" a's value: %d \n pointer to a's value: %d \n", a, *b); DoSomething(something_else()); int *b = do_some(arg_1, arg_2); if(do_something(arg1)){ a = b + 1; } else{ exit(1); }
return 0; }
Here we go. wrap every function call in a function-like macro called profile, except operators like main(), if(), while(), switch, case, etc.
Zachary James
You read the manual.
Justin Smith
YOU TOO LAZY TO gOOGLE THE answer, FaggoT?
Caleb Russell
>I've never heard of someone complaining about it. You still haven't. That was a nobody.
Bentley Bennett
Thank you for not python spacing.
Thomas Stewart
First to solve this gets my nudes (I'm a girl btw xoxo)
Adam Long
I don't get the joke. What's up with Perl users and Regex?