java - Regex for circle and polygon string with decimal/integer values -
i'm trying create regex patterns used in java following 2 strings:
circle ( (187.8562 ,-88.562 ) , 0.774 )
and
polygon ( (17.766 55.76676,77.97666 -32.866888,54.97799 54.2131,67.666777 24.9771,17.766 55.76676) )
please note
one/more white spaces may exist anywhere.exceptions not between alphabets.and not between digits of number. [updated]
circle , polygon words fixed not case sensitive.[updated]
for 2nd string number of point set not fixed.here i've given 5 set of points simplicity.
points set of decimal/integer numbers [updated]
positive decimal number can have + sign [updated]
leading 0 not mandatory decimal number [updated]
for polygon atleast 3 point set required.and first & last point set same (enclosed polygon) [updated]
any or suggestion appreciated.
i've tried as:
(circle)(\\s+)(\\()(\\s+)(\\()(\\s+)([+-]?\\d*\\.\\d+)(?![-+0-9\\.])(\\s+)(,)(\\s+)([+-]?\\d*\\.\\d+)(?![-+0-9\\.])(\\s+)(\\))(\\s+)(,)(\\s+)([+-]?\\d*\\.\\d+)(?![-+0-9\\.])(\\s+)(\\))
could please provide me working regex pattern 2 string?
i suggest remove space string before submitting regex.
circle:
circle\(\(-?\d+\.\d+,-?\d+\.\d+\),[-]?\d+\.\d+\)
polygon:
polygon\(\((-?\d+\.\d+\s+-?\d+\.\d+,)+-?\d+\.\d+\s+-?\d+\.\d+\)\)
circle including spaces:
circle\s*\(\s*\(\s*-?\d+\.\d+\s*,\s*-?\d+\.\d+\s*\)\s*,\s*-?\d+\.\d+\s*\)
polygon including spaces:
polygon\s*\(\s*\(\s*(-?\d+\.\d+\s+-?\d+\.\d+\s*,\s*)+\s*-?\d+\.\d+\s+-?\d+\.\d+\s*\)\s*\)
circle including spaces updated:
/circle\s*\(\s*\(\s*[+-]?\d*\.\d+\s*,\s*[+-]?\d*\.\d+\s*\)\s*,\s*[+-]?\d*\.\d+\s*\)/i
polygon including spaces updated:
/polygon\s*\(\s*\(\s*([+-]?\d*\.\d+)\s+([+-]?\d*\.\d+)\s*(,\s*[+-]?\d*\.\d+\s+[+-]?\d*\.\d+)+\s*,\s*\1\s+\2\s*\)\s*\)/i
Comments
Post a Comment