正则表达式替换FIX消息中的特定值

huangapple go评论55阅读模式
英文:

Regex replacing specific value within FIX message

问题

I'll provide the translated content:

对于我想要在Notepad++中使用正则表达式替换特定值的固定消息,给定以下示例(其中|是SOH字符):

> 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

我提出了以下正则表达式:

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

以获取:

> 49=DUMMYBROKER

即获取SOH字符之间以49=开头的值

(选择的结果是否包括或排除SOH是可选的,与是否仅选择值或包括49=也一样)

对于我上面的特定示例,我的正则表达式似乎有效,但我对正则表达式不太熟悉,不确定边缘情况(例如,如果消息中有类似值的标签或其他情况),或者是否这是最清晰的方法。

可以有人帮助审查吗?

英文:

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 ?

答案1

得分: 1

  • Ctrl+F
  • 查找内容:(?<=\x{01})49=[^\x{01}]+
  • 勾选 循环
  • 选择 正则表达式
  • 查找下一个
英文:
  • <kbd>Ctrl</kbd>+<kbd>F</kbd>
  • Find what: (?&lt;=\x{01})49=[^\x{01}]+
  • TICK Wrap around
  • SELECT Regular expression
  • <kbd>Find Next</kbd>

Explanation:

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

Screenshot:

正则表达式替换FIX消息中的特定值

答案2

得分: 0

\b49=[^|]+

这应该只匹配以确切的 49 开头,后跟 = 和一些右侧值的部分。

英文:

You may simply use:

\b49=[^|]+

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

<h2>Demo</h2>

huangapple
  • 本文由 发表于 2023年7月4日 22:03:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76613439.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定