Converting a VB.net regular expression to C#

I have a VB .net line of code that defines a regular expression. I need to convert the regular expressions to C#. But also I need to put into words what exactly it does. I believe it restricts input to 8 characters, with letters a-z or A-Z. Is my interpretation correct? Can anyone help me convert this regular expression to C#

Protected Const vbRegEx As String = "((?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d]))
LVL 2
brgdotnetcontractorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
A regular expression is a regular expression - it is not specific to a language.

In terms of the expression at least 8 characters with at least 1 lower 1 Upper case and 1 digit (\d)
0
Dan CraciunIT ConsultantCommented:
While regular expressions are not language specific, not all libraries implement the whole syntax.

In your case, both VB .NET and C# use the same library, so you should not have any surprises.

Below is the explanation token by token:

((?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d]))

Options: Case sensitive; Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture

Match the regex below and capture its match into backreference number 1 «((?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d]))»
   Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=.{8,})»
      Match any single character that is NOT a line break character (line feed) «.{8,}»
         Between 8 and unlimited times, as many times as possible, giving back as needed (greedy) «{8,}»
   Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=.*[a-z])»
      Match any single character that is NOT a line break character (line feed) «.*»
         Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
      Match a single character in the range between “a” and “z” (case sensitive) «[a-z]»
   Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=.*[A-Z])»
      Match any single character that is NOT a line break character (line feed) «.*»
         Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
      Match a single character in the range between “A” and “Z” (case sensitive) «[A-Z]»
   Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=.*[\d])»
      Match any single character that is NOT a line break character (line feed) «.*»
         Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
      Match a single character that is a “digit” (any decimal number in any Unicode script) «[\d]»
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
@Julian H.

A regular expression is a regular expression - it is not specific to a language.
That's not true at all. Different languages use different syntaxes. However, when referring to only .NET, then your statement is accurate.
0
Julian HansenCommented:
@Kaufmed,

Thanks for the heads up - just to clarify though (refer https://en.wikipedia.org/wiki/Comparison_of_regular_expression_engines)

As I understood it - different RegEx engines support different features of RegEx - but in terms of the syntax this conforms to the same general syntax (https://en.wikipedia.org/wiki/Regular_expression#Standards). There are some differences in delimiting expressions and specifying globals and case etc - but I was led to believe that when you said

.[a-z]+
OR
\d{3,2}

That in terms of the RegEx standard these were interpreted in the same way by all engines providing the engines supported those features. (Naturally if a feature is not supported then the question is moot as there is unlikely to be a translation but then that would be an symptom of functionality support rather than syntax?)

Is this thinking incorrect? Is it possible that the expression posted is valid in another environment but with different results
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.