2012-06-21 4 views
0

또 다른 정규식 질문 ....NET Regex 문자열 부정 부호

나는 C# 프로젝트 파일의 모든 강력한 리소스 링크를 새 번역 시스템에 대한 호출로 대체하는 프로젝트를 가지고 있습니다.

다음 두 줄에서는 첫 번째 줄만 가져와야합니다. 즉, ResourceManager 호출을 제외하고 싶습니다.

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

나는 잘 작동 다음 정규식을 작성하지만 불행히도 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+) 

내가 필요한 것 (또는 나는 내가 필요가 있다고 생각 무엇을)을 부정적 예측이 ... 그 음/긍정적 lookaheads은/lookbehinds은 ... 나에게 내가이 lookahed 또는 lookbehind을 올바르게 배치 ... 아니면 더 나은 경우에 사용하는 방법을 결코 확실 해요 없기 때문에 내가 그들을 필요로 실현 두통 매번를 제공

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

'ResourceManager'가없는 문자열 만 가져오고 싶습니까? 그렇다면'String.Contains' 함수를 사용할 수 있습니다. if (string.Contains ("ResourceManager") == false) {...}' –

답변

1

내가 너를 올바르게 이해했다면 너는 옳은 일을하고 있지만 부정적 예측을 잘못했다. key :

[^\w\.]Resources\.(?<global_key>\w+)\.(?!ResourceManager)(?<key>\w+) 
+0

나는 바보입니다. 당연하지. 고마워요 :) – Mirek

+0

@ Motig 아무 문제, 행운을 빌어 요! ;) –

+1

[Mastering Lookahead and Lookbehind] (http://www.rexegg.com/regex-lookarounds.html)의 빠른 링크가이 문제에 직면 해 있습니다. –