java - Regex - starts with OPERATION and must be followed by either an integer or double -
so have follow input string
operation: 12, 12.32, 54.3332
operation can of min, max, sum. regex should accept strings start of 3 words follow colon , followed either integer or double.
i have been googling , fidling around hours before decided turn guys.
thanks time!
edit:
so far have ended regex
^[max:sum:average:min:(\\d+(\\.\\d+)?), ]+$
it matches "max: " correct "max:" , "ma: . matches strings of following format : "max: 12, 12.3323......"
you misunderstand meaning of []
. these refer single character alternatives.
so [max:sum:average:min:(\\d+(\\.\\d+)?), ]
either m
or a
or x
or .... mmmmm
should match.
you may want more this:
^(max|sum|average|min): (\\d+(\\.\\d+)?(, (?=.)|$))+$
explanation:
(max|sum|average|min)
either max
, sum
, average
or min
.
": "
refers actual characters :
, space.
\\d+(\\.\\d+)?
had before.
", "
refers actual characters ,
, space.
(?=.)
look-ahead. checking following characters (?=)
matches single character (.
) (thus not end-of-string) there isn't ", "
required @ end.
, (?=.)|$
either ", "
not @ end or nothing @ end.
alternative: not using look-ahead
^(max|sum|average|min): (\\d+(\\.\\d+)?(, \\d+(\\.\\d+)?)*)$
Comments
Post a Comment