Bloomberg Bulk Data Regex Parsing

Viewed 179

I am trying to parse the result from Bloomberg Data Licence when they return a bulk data format.

This string is typically a bunch of key value pairs separated by a semi colon and indicated by a number for the data type they are.

The first three numbers are the fact that it is a 2d array with 4 results. The number before the value is the datatype, e.g. 5 is date and 3 is number, however this is not important right now.

Here is an example data response: ;2;4;2;5;20181201;3;102;5;20191201;3;101.000000;5;20201201;3;100.000000;5;20211201;3;100.000000;

Expected return would be to grab the dates and the values from this string, and the result would be:

20181201 - 102

20191201 - 101.000000

20201201 - 100.000000

20211201 - 100.000000

I have tried the following regex using replace:

5;(?P<date>\d{8})|\;3;(?P<value>\w+.\w+) and using replace value \1, \2 which returns the following:

;2;4;2;20181201,,102;5;20191201,101.000000;20201201,,100.000000;20211201,,100.000000;

I am still getting the return value of ;2;4;2 - how do I ignore these first three grouped values in my regex?

P.S. This is just example data, doesn't actually refer to anything

1 Answers

In your pattern, you use \w+.\w+ which matches 1+ word characters, 1 time any char using the dot and again 1+ word characters. It expects to match at least 3 characters.

That is why in the example data you match 102;5 instead of 102 because the dot will match the ; and the last \w+ will match the 5.


If you only want the data in the named groups data and value, you can use lookarounds instead.

To match the digits with an optional decimal parts, you could use \d+(?:\.\d+)? instead.

Instead of replacing the values, you should get the match from the group.

(?<=5;)(?P<date>\d{8})|(?<=;3;)(?P<value>\d+(?:\.\d+)?)

Regex demo

Related