• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to split string with rules  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need your regular expression skill to help with finetuning this Java String.split(",") that is not retaining all the delimiter correctly. Below is the type of input string used:





i am looking for a clean as simple solution instead of with StringTokenizer or LinkedList. Would finetuning the regular expression achieve the objective? Otherwise, please advice on other possible better solution.

Thanks in advance,
 
Ranch Hand
Posts: 679
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd be better off using a 3rd party CSV library rather than trying to write your own regex.
See AccessingFileFormats for a few suggestions (under the Excel section)
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I completely agree with Adrian on this one.
The apparent simplicity of the CSV format can be deceptive, and trying to parse it using your own regex solution is often not the way to go.
Save yourself some time and frustration and go with a ready-made CSV parser (e.g. opencsv, apache commons CSV, CsvJdbc)
 
Shazia Bashir
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks folks. OpenCSV works like a charm.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!