Results 1 to 6 of 6
- 01-03-2011, 07:03 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 6
- Rep Power
- 0
problem with using regular expression
hello
I have huge strings and from which I want to extract this form: [ *,* ] using regular expression.
here is the fragment of the string.
{ "type": "Polygon", "coordinates": [ [ [ 32.090000, 41.110000 ], [ 32.090537, 41.110510 ], [ 32.091100, 41.110991 ], [ 32.100000, 41.114142 ], [ 32.100740, 41.114123 ], [ 32.101478, 41.114065 ] ] ]}
- 01-03-2011, 07:08 PM #2
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
Try the following
".*\\[(.*\\,.*)\\].*"
Then you can use the group(int group) method of the Matcher class to access the matching capture groups.
...if you want the result to include the square brackets, then move those inside the parentheses.
- 01-03-2011, 07:14 PM #3
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
or better: use a json parser like gson or jackson :D
- 01-03-2011, 07:35 PM #4
Member
- Join Date
- Feb 2009
- Posts
- 6
- Rep Power
- 0
thank you
I am actually JSON format.
So how can I use JSON and can you recommend any reference material ?
regards
- 01-03-2011, 07:45 PM #5
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
JSON
and gson guide Gson User Guide - gson
+
jackson tutorial: Jackson JSON Processor - Tutorial
are you sure, that you want an array in an array in an array ? :D ("coordinates": [ [ [ ) ?
thats strange imo :D
here is an little gson example with your json string
simple java class
parseJava Code:class Shape { private String type; private Double[][][] coordinates; // or private List<Double[][]> coordinates; or something similar /** * @return the type */ public String getType() { return type; } /** * @return the coordinates */ public Double[][][] getCoordinates() { return coordinates; } }
Java Code:public static void main(String[] args) { String json = "{ \"type\": \"Polygon\", \"coordinates\": [ [ [ 32.090000, 41.110000 ], [ 32.090537, 41.110510 ], [ 32.091100, 41.110991 ], [ 32.100000, 41.114142 ], [ 32.100740, 41.114123 ], [ 32.101478, 41.114065 ] ] ]} "; Shape s = new Gson().fromJson(json, Shape.class); System.out.println(s.getType()); for (Double[][] arr : s.getCoordinates()) { for (Double[] doubles : arr) { System.out.println(Arrays.toString(doubles)); } } }
- 01-03-2011, 07:59 PM #6
Member
- Join Date
- Feb 2009
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Help with regular expression
By mr.ab18 in forum New To JavaReplies: 2Last Post: 08-06-2010, 10:01 PM -
regular expression
By prof.deedee in forum JDBCReplies: 3Last Post: 02-19-2010, 11:15 AM -
regular expression
By QkrspCmptPop in forum Advanced JavaReplies: 8Last Post: 01-20-2010, 03:55 AM -
regular expression
By ras_pari in forum Advanced JavaReplies: 27Last Post: 10-07-2009, 12:25 PM -
Regular Expression Problem
By daflores in forum Advanced JavaReplies: 8Last Post: 02-10-2009, 06:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks