3

テストデータ

1: "Abc.TestCase For TestCase By Abc.TestCase Using TestCase"           --> 2 matches 
2: "(Abc.TestCase For TestCase By Abc.TestCase Using TestCase)"         --> 2 matches
3: "(TestCase For TestCase By Abc.TestCase Using TestCase)"             --> 3 matches
4: "(Abc.TestCase For TestCase By Abc.TestCase Using Xyz.TestCase.Sub)" --> 1 match
5: "(Abc.TestCase For TestCase By Abc.TestCase Using Xyz.TestCase1)"    --> 1 match

ターゲットは、未修飾の「TestCase」を取得することです

以下を試しました

[^.]\bTestCase\b[^.]

これは機能しますが、一致として "(TestCase" "TestCase)" を返す 2 & 3 ケースで失敗し、置換で誤った結果を導きます。

これで終わりです!

ここで助けていただければ幸いです。

4

2 に答える 2

1

Your are close

The problem is that ) and " are considered word boundaries

So if you add the exceptions to the character class like so

[^.]\bTestCase\b[^").]

your regex will match only the first occurrence of TestCase

Update 1

enter image description here

BTW, looking at your sample input I think " TestCase " as a regex would work as well. But maybe you have more edge cases

于 2012-06-06T10:12:52.777 に答える