I want to split a pipe( | ) delimited file using regex only and extract a particular field at nth position. My current solutions works fine until a blank field appears. I am unable to figure out what i am doing wrong.
Sample Data:
asdw|qwe|23344|as||sada||ssss|sdd
My partially working solution:
^((?:[^|] \|){3})(?P<error>[^|] )
https://regex101.com/r/bXvo4T/1
CodePudding user response:
Just need to swap the 'One or more token
' with a 'Zero or more token *
' as it looks like it's getting stuck with no chars between the two pipes.
I think the following should give you the result you are looking for:
^((?:[^|]*\|){3})(?P<error>[^|] )