2

I know this (or similar) has been asked a hundred times - but I really need help now :D The strings the regex should match.

Note: n is in the range of INTEGER_MIN - INTEGER_MAX

{number}
{number(1-n)}
{number(1-n,-n-n)}
{number(1-n,-n-n,0-n)}

If the pattern matches it should result in 3 seperate capture groups, with this results. All groups should be optional - so that if request in for example Java they return null.

1: 1-n
2: -n-n
3: 0-n

What I've tried:

\{number(?:\(([1-9])(?:(?:,)([0-9])){0,2}\))?\}

This obviously isn't right and is only containing 2 groups (m.groupCount())

4

1 回答 1

2

Okay, from what I deduced, I would do this:

\{number(?:\((\-?\d+)(?:\,(\-?\d+))?(?:\,(\-?\d+))?\))?\}

Then carry out operations on the captured groups to valid the range of the integers such as...

[Pseudo code since I don't know what language you are using]

captured integers = "capture1", "capture2", "capture3"
if{("capture1" < "capture2" && "capture1" > "capture3") ||
   ("capture1" > "capture2" && "capture1" < "capture3")} {

    Do something

} else {

    Do something else; like reject or throw error

}
于 2013-05-20T17:52:54.853 回答