views:

82

answers:

1

I am trying to write a simple regex to match a percentage value range 1%-100%

Is there a better way to write this?

^([1-9]|[1-9][0-9]|100)%$
+4  A: 

You can make it a bit shorter:

^([1-9][0-9]?|100)%$
SLaks
Thanks, this is the type of optimization I knew I was missing.
gmcalab
Here's a better one ([1-9]\d?|100)%$ it will make the OP even more happy: -2 chars.
Pop Catalin
it doesn't provide any measurable speed-up, though
SilentGhost
@SilentGhost, that's ok though since the question wasn't (specifically) about performance.
macek
Yes I had no performance issue's just thought there might be a better approach.
gmcalab