Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!