2

I have to develop a program that validates input from the user. String format is:

ebill (ao|aio|block) [email protected](any email address)

Now i'm looking for a solution with the following conditions:

  • ebill ao or ebill aio checks for third argument which is an email address.
  • but if i got ebill block then my regular expression wouldn't check for email address.

2 Answers 2

3

I would do it this way:

ebill (((ao|aio) [email protected])|block)
Sign up to request clarification or add additional context in comments.

Comments

2

The short answer is don't. Parse the list of arguments by splitting your string on spaces, and act upon each one as needed.

1 Comment

I disagree with you. Regular expression engine is very optimized and fast. Splitting string to chunks by spaces is not more effective than running precompiled regular expression against this string. Moreover String.split() uses regular expressions anyway.

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.