Need to fix my regex

Posted by Misha Zaslavsky on Stack Overflow See other posts from Stack Overflow or by Misha Zaslavsky
Published on 2014-08-23T10:09:44Z Indexed on 2014/08/23 10:20 UTC
Read the original article Hit count: 387

Filed under:
|
|

I am trying to match a string to a regex pattern, but have some problems.

My string could have 3 forms:

  1. [dbo].[Start]
  2. dbo.Start
  3. Start

This is my regex:

"^((\[)?dbo(\])?)?(\.)?(\[)?Start(\])?$"

All 3 forms returns success but there are some more options such as: [dboStart or dbo[Start

I know that this is because it is optional, but how could I make dependencies when making optional, so that if one optional has value then the second optional must have a value too.

Could you help me please to fix this?

Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql