Using regex to reorganize a data string in a file to examinine it for errors

Viewed 21

I have a data file that contains numbers which are 8-digit SKUs followed by quantities. The 2-pieces of data are separated by a + I want to use regex to place the SKU and quantities on a line by themselves so I can examine the data for errors.

Example: Data I get is - 206120651+206132791+206120651+

I want it to display as

20612065 1 20613279 1 20612065 1

Using carriage return to display each SKU and quantity on a separate line.

1 Answers

Are you shure to use regex?

Regex pattern to catch only nine digit numbers is \d{9}

Regex pattern to catch only eight digit numbers is \d{8}

But in most programming languages there is a replace function. For example in python:

'206120651+206132791+206120651+'.replace("1+", " 1\n")
>>> 20612065 1
... 20613279 1
... 20612065 1
Related