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.

4

2 回答 2

1

You can try the regex:

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

See it

于 2012-10-19T12:43:14.270 回答
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+)*)?$".

于 2012-10-31T10:17:08.170 回答