1

I need a regex code which will detect format like this "1-2-2-2-1-5".This can be longer string or shorter like "1-8-5-6".I mean, the length is not entirely clear.But format is certain one int and one '-'. i tried "(^[-][0-9]){,}" this.But i have no idea about Regex. Can someone help me?Thnx.

2
  • what happened when you tried that? Commented Oct 19, 2012 at 12:42
  • nothing, only pattern not matches with my string. Commented Oct 19, 2012 at 14:03

2 Answers 2

1

You can try the regex:

^[0-9](?:-[0-9])*$

See it

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

Comments

0

I found a bug.
My question missing. In situation "1-12-12-1" regex is not matched.
So I changed my regex with "^(\d+(-\d+)*)?$".

Comments

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.