0

Just another regex question...

I have a project to replace all strong resource links in a C# project files with calls for our new translation system.

For the following two lines, i need to get only the first one. That means, I want to exclude the ResourceManager calls.

Resources.SomeGlobalResxFile.SomeKey
Resources.SomeGlobalResxFile.ResourceManager //mostly followed with GetString

I've written the following regex, which works well but unfortunately includes the ResourceManager

//"Resources" must have no alfa or dot character before them -> [^\w\.]
//The link is consisted of a global key (the first parenthesis linking 
//the RESX file) and the resource key
[^\w\.]Resources\.(?<global_key>\w+)\.(?<key>\w+)

What i need (or what I think i need) is the negative lookahead...those negative/positive lookaheads/lookbehinds give me headache everytime I realize I need them because I'm never sure how to place them correctly...or if it's better to use a lookahed or a lookbehind...

//still includes the ResourceManager
[^\w\.]Resources\.(?!ResourceManager)(?<global_key>\w+)\.(?<key>\w+)
[^\w\.]Resources\.(?<global_key>(?!ResourceManager)\w+)\.(?<key>\w+)
4

1 回答 1

1

If I understood you correctly, you are making everithing right, but misplaced the negative lookahead. It should be within a key:

[^\w\.]Resources\.(?<global_key>\w+)\.(?!ResourceManager)(?<key>\w+)
于 2012-06-21T08:00:46.267 回答