Test data
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
Target is to obtain the unqualified "TestCase"
have tried the following
[^.]\bTestCase\b[^.]
while this works it fails with 2 & 3 case where it returns "(TestCase" "TestCase)" as matches, which would then lead erroneous results in the replacement.
at a wit's end for this !
would appreciate some help here.
I think this is what you're looking for:
(?<!\.)\bTestCase\b(?!\.)
In other words, you want to match the whole word TestCase (i.e., not preceded or followed another word character), but not if it's immediately preceded or followed by .. Here's a slightly neater version:
(?<!\.\w)TestCase(?!\.\w)
The way you wrote the question, it sounds like you also want to exclude matches that are preceded or followed by parentheses, like (TestCase or TestCase), but I finally realized you just don't want to include the parens in the match. Replacing the negated character classes ([^.]) with negative lookarounds ( (?<!\.) and (?!\.]) ) meets that requirement because lookarounds don't consume what they match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With