0

I have a block of data, which essentially consist of pipe-seperated fixed messages (back to back).

I am using python, and the only way I can think of, is to find the index of the 8=FIX.4.2 tag (denoting the start of a message), work my way back to the end of the previous message, and determine the message that way.

I was wondering if this could be achieved any other way (regex for example). I am not sure how to apply the the grouping construct in regex here.

As an example of the data I am looking at:

8=FIX.4.2|9=122|35=D|49=hello|56=def|34=2|52=19700116-14:18:06.790|11=000007|55=DUMMY|54=#|38=1000|40=1|44=77|60=19700116-14:18:06.790|59=0|10=148|8=FIX.4.2|9=122|35=D|49=hello|56=def|34=2|52=19700116-14:18:06.790|11=000007|55=DUMMY54=#|38=1000|40=1|44=77|60=19700116-14:18:06.790|59=0|10=148|
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Pradyot
  • 2,897
  • 7
  • 41
  • 58

4 Answers4

2

You can just use 8=FIX.4.2 as the argument to split().

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Beat me to it. If you know you always have complete messages and the delimiter is always the same just split it then split again on the pipe and you are ready to work. – Omnikrys Sep 13 '12 at 14:55
0
messages = your_input.split('8=FIX.4.2|')
messages = [ m.split('|') for m in messages ]
Andy Hayden
  • 359,921
  • 101
  • 625
  • 535
0

The problem with split is it removes the delimiter from the resultant expressions. so this is the return from split on the data I have.

['', '9=122|35=D|49=hello|56=def|34=2|52=19700116-14:18:06.790|11=000007|55=IYH|54=#|38=1000|40=1|44=77|60=19700116-14:18:06.790|59=0|10=148|', '9=155|35=D|49=hello|56=def|34=2|52=19700116-14:18:06.790|11=000007|55=IYH|54=#|38=1000|40=1|44=77|60=19700116-14:18:06.790|59=0|10=148|']

I think the approach I am looking for would involve use of grouping as well as re.finditer.

I will post the expression when done(since I have never used it before).

Pradyot
  • 2,897
  • 7
  • 41
  • 58
0

expr = r'8=FIX\.4\.2.*?10=\d+\|' msglist = re.findall(expr,data)

this seems to work in the manner I hoped.

Pradyot
  • 2,897
  • 7
  • 41
  • 58