Search code examples
javaregextalend

How to split string into columns in java


I am parsing file which has following type of rows using Talend, i have tried tFileInputDelimted component to parse it, but text en-closer "'" not working.

1, 0, 1, 73, 0, 'root.1', 'Root Asset', '{"site":{"6":1,"2":1},"core":{"6":1}}'

I need a output in following format.

1
0
1
73
0
root.1
Root Asset
{"site":{"6":1,"2":1},"core":{"6":1}}

Edited: Sample row

`90, 'Loader Menu', '', '<div class="arrowlistmenu">\r\n<h3 class="menuheader"><a href="index.php/component/ordersoncalendar">View Orders</a></h3>\r\n<div class="shrink_div"> </div>\r\n<h3 class="menuheader"><a href="index.php/component/reportmaster/?task=report_details">Time Sheets</a></h3>\r\n<div class="shrink_div"> </div>\r\n<h3 class="menuheader"><a href="index.php/component/availabilitycalendar?task=availability">Update Availability</a></h3>\r\n<div class="shrink_div"> </div>\r\n<h3 class="menuheader"><a href="index.php/component/workers?task=update_personal_info">Update Personal Information</a></h3>\r\n<div class="shrink_div"> </div>\r\n<h3 class="menuheader"><strong><a href="index.php/component/workers?task=ask_password_change">Change Password</a></strong></h3>\r\n<div class="shrink_div"> </div>\r\n</div>', 1, 'loader-menu-position', 0, '0000-00-00 00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, 'mod_custom', 2, 1, '{"prepare_content":"1","backgroundimage":"","layout":"_:default","moduleclass_sfx":"","cache":"1","cache_time":"900","cachemode":"static"}', 0, '*'`

and output expected for this row is.

90 'Loader Menu' '' '<div class="arrowlistmenu">\r\n<h3 class="menuheader"><a href="index.php/component/ordersoncalendar">View Orders</a></h3>\r\n<div class="shrink_div"> </div>\r\n<h3 class="menuheader"><a href="index.php/component/reportmaster/?task=report_details">Time Sheets</a></h3>\r\n<div class="shrink_div"> </div>\r\n<h3 class="menuheader"><a href="index.php/component/availabilitycalendar?task=availability">Update Availability</a></h3>\r\n<div class="shrink_div"> </div>\r\n<h3 class="menuheader"><a href="index.php/component/workers?task=update_personal_info">Update Personal Information</a></h3>\r\n<div class="shrink_div"> </div>\r\n<h3 class="menuheader"><strong><a href="index.php/component/workers?task=ask_password_change">Change Password</a></strong></h3>\r\n<div class="shrink_div"> </div>\r\n</div>' 1 'loader-menu-position' 0 '0000-00-00 00:00:00' '0000-00-00 00:00:00' '0000-00-00 00:00:00' 1 'mod_custom' 2 1 '{"prepare_content":"1","backgroundimage":"","layout":"_:default","moduleclass_sfx":"","cache":"1","cache_time":"900","cachemode":"static"}' 0 '*'

As I said file has millions of rows it is very difficult to put all the formats of rows here but at least we get some thing which can parse above lines then that is also acceptable. please suggest how can I achieve it, as this file has millions of records.


Solution

  • You can use the following regex:

    \\s*,\\s*(?=(?:(?:[^']*'){2})*[^']*$)
    

    See DEMO