简体   繁体   English

匹配模式的有效方法 - python

[英]Efficient way for matching patterns - python

I wondering how to do properly a matching model or something similar.我想知道如何正确匹配 model 或类似的东西。

Here is my matching data.这是我的匹配数据。

CFI Code ESMA Type  
DB****  RFOBLIGAC   
E*****  RV  
R*****  DERECHOEMIS 
O**S*S  FUTOPRV 
O**S*N  SWAPRV               
O**I*S  FUTOPR

For the first example 'DB****' I want to obtain the world 'RFOBLIGAC', but here is the problem, the **** can be whatever character.对于第一个示例“DB****”,我想获得世界“RFOBLIGAC”,但问题是,**** 可以是任何字符。

For example if my CFI is 'DB4902' is the same as 'DB****' so the result would be 'RFOBLIGAC'.

The problem is for the last 3 examples, as you can see they change only letter 4, and last one.问题在于最后 3 个示例,您可以看到它们仅更改了字母 4 和最后一个。

I want an idea how to plain what is the best solution to solve it.我想知道如何明确解决它的最佳解决方案。

I just posted 6 lines, but I have more than 30 matching patterns.我刚刚发布了 6 行,但我有 30 多个匹配模式。

Any idea?任何想法?

The simplest solution is to just write a regular expression for each pattern, and test each in sequence.最简单的解决方案是为每个模式编写一个正则表达式,并依次测试每个模式。 Here, you'd probably want a list of (CFI-regex, ESMA-type) pairs.在这里,您可能需要(CFI-regex, ESMA-type)对的列表。

There are more elegant solutions (eg. a trie), but for 30 patterns, this is probably fine and almost no work.有更优雅的解决方案(例如 trie),但对于 30 种模式,这可能很好,几乎没有工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM