java - Regex for circle and polygon string with decimal/integer values -


i'm trying create 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

  1. one/more white spaces may exist anywhere.exceptions not between alphabets.and not between digits of number. [updated]

  2. circle , polygon words fixed not case sensitive.[updated]

  3. for 2nd string number of point set not fixed.here i've given 5 set of points simplicity.

  4. points set of decimal/integer numbers [updated]

  5. positive decimal number can have + sign [updated]

  6. leading 0 not mandatory decimal number [updated]

  7. 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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -