Results 1 to 3 of 3
- 04-19-2011, 06:31 PM #1
Member
- Join Date
- Apr 2011
- Location
- Florida
- Posts
- 2
- Rep Power
- 0
How to use regex and split to solve a problem
I have a string:
"BIDU","Baidu, Inc","4/19/2011",147.28,45.89
When I do a split(",") on the string, the comma inside the double quotes causes an extra unwanted split. Is there a regex pattern that would split the string only at commas which are not inside double quotes. I have no control over the input as it comes from a web service.
- 04-19-2011, 07:00 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Regex cant count, so it cant check if there is an open quote :)
But the String contains only other inner Strings "..." or a double value or?
-->Java Code:String s ="\"BIDU\",\"Baidu, Inc\",\"4/19/2011\",147.28,45.89"; Matcher m = Pattern.compile("\".*?\"|\\d+\\.\\d+").matcher(s); while(m.find()){ System.out.println(m.group()); }
"BIDU"
"Baidu, Inc"
"4/19/2011"
147.28
45.89
- 04-19-2011, 08:31 PM #3
Member
- Join Date
- Apr 2011
- Location
- Florida
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Regex and split
By sunde887 in forum New To JavaReplies: 2Last Post: 02-14-2011, 12:54 AM -
Regex problem
By Nimyz in forum Advanced JavaReplies: 4Last Post: 05-14-2010, 07:17 AM -
split() function problem.
By robWhittle in forum New To JavaReplies: 2Last Post: 04-09-2010, 01:34 PM -
split method problem
By javanew in forum New To JavaReplies: 1Last Post: 04-02-2010, 05:50 PM -
split problem
By mac in forum New To JavaReplies: 4Last Post: 01-02-2010, 04:46 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks