using regex to capture data instead of splitting. and added testcases.