Regex replacing specific value within FIX message

121 Views Asked by At

For any fixed message I wanted to use regex in notepad++ to replace particular values.

Given an example like below (where the | is the SOH character)

8=FIXT1.1|9=709|35=y|34=53|49=DUMMYBROKER|56=<client_ID>|52=20210211- 12:12:37.358847|55=AUD/CAD|55=AUD/CHF|55=AUD/JPY|55=AUD/NZD|55=AUD/USD|55= CAD/CHF|55=CAD/JPY|55=CHF/JPY|55=EUR/AUD|55=EUR/CAD|55=EUR/CHF

i came up with the regex

[^\x{01}]\49=[^\x{01}]

In order to get

49=DUMMYBROKER

I.e get a value inbetween the SOH character, and starts with 49=

(Whether the selected result includes or excluded the SOH is optional, same with whether it just selects the value or with the 49= too)

For my particular example above my regex seems to work, however I'm not too experienced in regex and unsure about edge cases (such as if the message has similar values within another tag or something) or whether it is the cleanest

Could someone help to review ?

2

There are 2 best solutions below

2
Tim Biegeleisen On

You may simply use:

\b49=[^|]+

This should match only the portion starting with exactly 49, followed by = and some right hand side value.

Demo

0
Toto On
  • Ctrl+F
  • Find what: (?<=\x{01})49=[^\x{01}]+
  • TICK Wrap around
  • SELECT Regular expression
  • Find Next

Explanation:

(?<=\x{01})     # positive lookbehind, make sure we have SOH before
49=             # literally
[^\x{01}]+      # 1 or more any character that is not SOH

Screenshot:

enter image description here