user1899731
user1899731

Reputation: 71

Find particular string pattern and replace in c#

I have a string which contains word “Limited” or “Ltd”. My requirement is to remove any text in brackets "( )" after the same words “Limited” or “Ltd” in the given input string.

For example "Abcd Ltd (North)" will become "Abcd Ltd" but “Abc (North)” will remain “Abc (North)”

Also "ABCD Ltd test (North)" will remain same as it is.

I am trying to find out regular expression in c#, which can solve the above issue?

Any help is appreciated.

Upvotes: 0

Views: 241

Answers (1)

Suhjin Park
Suhjin Park

Reputation: 480

In that case I would use Lookbehind.

The use would be like this:

(?<=(Ltd|Limited))\s?\(.*?\)

And use Regex.Replace to remove the text.

Upvotes: 3

Related Questions