开发者

Regular expression with more than one ~ (not) part

开发者 https://www.devze.com 2023-03-31 09:22 出处:网络
I\'m using the following regular expression: ~(sizeof)\\(<int|long>\\) to match: blah blah (int)variable blah blah

I'm using the following regular expression:

~(sizeof)\(<int|long>\)

to match:

blah blah (int)variable blah blah
blah blah (long)variable blah blah

but not:

blah blah sizeof(int) blah blah

That all works. Now, I want to further not match:

HMODULE (WINAPI *fnPtr)(int) = NULL;

so I tried:

~(sizeof|fnPtr\))\(<int|long>\)

but it still matches the fnPtr line. How should I alter the regular expression to not match that line?

(I'm using the regular expression search in Visual Studio 2005.)

(I've greatly simplified the regular expression in as much as the int|long part is really int|long|... where ... is about 40 other types.)

Edit:

Nevermind, I've solved it. You need to do:

~(sizeof|(fnPtr.))\(<int|long>\)

which is replace the fnPtr\) with (fnPtr.), so 开发者_开发问答that the . matches the bracket, and so that the . is associated with fnPtr.


Try this: [\w\s]+ \((int|long)\)[\w ]+

Here's a demo: http://regexhero.net/tester/?id=d18853f4-a737-4509-8c7b-babd0e9272d2

Note: Read my comment to your post. This is standard regex, not VS regex. You can adopt it accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消