I have a String:
AAA foobarfoobarfoobar foo baar bar foo BBB and so on
After the Replace it should looke like:
AAA foobarfoobarfoobar foo baar bar foo
basically the BBB and everything behind it shall be stripped. so my first thought was an expression like:
BBB.*
Which actually does the Job. But i only want this to work, if BBB stands behind an AAA, so that
BBB bbb AAA aaa BBB ccc
whill be replaced to
BBB bbb AAA aaa
the first BBB is staying because there is no AAA in front of it.
my thought was an expression like
AAA.*?BBB.*
this would match the correct parts i think, but it will also kill the whole thing. So I know there are placeholders or something, but couldnt find out how to use them correctly. How is this done?
Try someting like this
(?<=AAA.*)is a look behind assertion, .net is able to handle them without length restriction, so it should be working for you.The other solution would be
and replace with the content from the capturing group 1