0

I'd like to have a RegEx in Powershell which matches following expressions:

  • MusMax / musmax
  • MusMax1 / musmax1

But it should not match with:

  • tMusMax / tmusmax
  • tMusMax1 / tmusmax1
  • itMusMax / itmusmax
  • itMusMax1 / itmusmax1

The code that I have until now is following:

((?=.*[a-zA-Z])(?=.*\d).{6,7})

My Problem is that this RegEx only matches to the expressions with a digit in the last place, but the digit is optional so it should not match only these.

Thanks for any help!

2
  • 1
    add a ? after the digit (\d) Commented Oct 9, 2015 at 14:19
  • You haven't defined what your regex should match very well. Can you write one sentence of plain English for that? Commented Oct 9, 2015 at 14:23

1 Answer 1

2

Could it be as simple as:

\b[a-zA-Z]{6}\d?\b

(My interpretation of your samples was "Whole words of six ASCII characters that end in an optional additional digit.")

Sign up to request clarification or add additional context in comments.

1 Comment

Thank Tomalak for the quick answer! Your Interpretation was right and so was your RegEx.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.