[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

RegEx gods requiered

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 25
Thread images: 7

File: CZx0dgG.jpg (11KB, 411x184px) Image search: [Google]
CZx0dgG.jpg
11KB, 411x184px
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.
>>
Use a fucking parser generator instead dipshit.
>>
>>58698506
like for example...
>>
>>58698521
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.
>>
>>58698484
That will be a bitch, anon.
http://stackoverflow.com/questions/1395177/regex-to-exclude-a-specific-string-constant

If you have the time, use some parser generator, like >>58698506 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.
>>
>>58698484
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
}
>>
>>58698595
Thanks a lot anon.

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.
>>
>>58698656
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.
>>
>>58698656
>python spacing
post disregarded
>>
>>58698694
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.
>>
File: xkcd-208-regular_expressions.png (25KB, 600x411px) Image search: [Google]
xkcd-208-regular_expressions.png
25KB, 600x411px
>>58698670
Paste some example code and I'll try to work my RegEx magic.
>>
>>58698750
>posting xkcd
ignore this guy, his regexes probably suck
>>
File: xkcd-1171-perl_problems.png (21KB, 548x205px) Image search: [Google]
xkcd-1171-perl_problems.png
21KB, 548x205px
>>58698759

They probably will, but if it can be done in RegEx I can do it. Probably.
>>
>>58698820
Never mind, spoken like a true regex user. Carry on, then
>>
>>58698750

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.
>>
File: special_char_regex.png (107KB, 1212x3296px) Image search: [Google]
special_char_regex.png
107KB, 1212x3296px
>>58698484
You read the manual.
>>
>>58698484
YOU TOO LAZY TO gOOGLE THE answer, FaggoT?
>>
File: muibem.jpg (10KB, 64x64px) Image search: [Google]
muibem.jpg
10KB, 64x64px
>>58698732
>I've never heard of someone complaining about it.
You still haven't. That was a nobody.
>>
>>58699083
Thank you for not python spacing.
>>
>>58699083
First to solve this gets my nudes (I'm a girl btw xoxo)
>>
>>58698820
>>58698750
I don't get the joke.
What's up with Perl users and Regex?
>>
File: 1379348739017.jpg (80KB, 720x960px) Image search: [Google]
1379348739017.jpg
80KB, 720x960px
>>58699083

(?!^.*[(]{1,}.*$)^.*
>>
File: 1443715329189.jpg (233KB, 1280x1280px) Image search: [Google]
1443715329189.jpg
233KB, 1280x1280px
>>58699083
>>58699463

((?!^.*[main(]{5,})(?!^.*[if(]{3,}.*)(?!^.*[while(]{6,}.*)(?!^.*[switch]{6,}.*)(?!^.*[case]{4,}.*))^.*
>>
>>58699414
perl does basically everything with regex.
>>
>>58699083
Is profile going to play nicely with macros?
Thread posts: 25
Thread images: 7


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.