如何使用PatternMatchingCompositeLineMapper在Spring批处理中实现复杂的模式匹配 [英] how to implement complex pattern matching in Spring batch using PatternMatchingCompositeLineMapper
问题描述
我们如何在Spring Batch中实现模式匹配,我正在使用org.springframework.batch.item.file.mapping.PatternMatchingCompositeLineMapper
我知道我只能用吗?或*在此处创建我的图案.
How can we implement pattern matching in Spring Batch, I am using org.springframework.batch.item.file.mapping.PatternMatchingCompositeLineMapper
I got to know that I can only use ? or * here to create my pattern.
我的要求如下: 我有一个固定长度的记录文件,在每个记录中,我在第35和第36位有两个字段,这些字段给出了记录类型 例如,"05"下方的记录类型位于第35和36位,记录的总长度为400.
My requirement is like below: I have a fixed length record file and in each record I have two fields at 35th and 36th position which gives record type for example below "05" is record type which is at 35th and 36th position and total length of record is 400.
0000001131444444444444445589868444050MarketsABNAKKAAAAKKKA05568551456 ...........
0000001131444444444444445589868444050MarketsABNAKKAAAAKKKA05568551456...........
我试图编写正则表达式,但是它不起作用,我知道只能使用两个特殊字符,即*和?.
I tried to write regular expression but it does not work, i got to know only two special character can be used which are * and ? .
在这种情况下,我只能这样写 ????????????????????????????????????? 05 ????????????? ... ................
In that case I can only write like this ??????????????????????????????????05?????????????..................
但这似乎不是一个好的解决方案.
but it does not seem to be good solution.
请提出如何编写此解决方案的建议,在此先感谢您的帮助
Please suggest how can I write this solution, Thanks a lot for help in advance
推荐答案
PatternMatchingCompositeLineMapper
使用org.springframework.batch.support.PatternMatcher
的实例进行匹配.重要的是要注意PatternMatcher
不使用真正的正则表达式.它使用了更接近蚂蚁模式的东西(代码实际上是从Spring Core中的AntPathMatcher
提出的).
The PatternMatchingCompositeLineMapper
uses an instance of org.springframework.batch.support.PatternMatcher
to do the matching. It's important to note that PatternMatcher
does not use true regular expressions. It uses something closer to ant patterns (the code is actually lifted from AntPathMatcher
in Spring Core).
话虽如此,您有三种选择:
That being said, you have three options:
- 使用您所指的模式(因为没有捷径可以指定正则表达式中应检查的?的数量).
- 创建您自己的使用正则表达式进行映射的复合
LineMapper
实现.
- Use a pattern like you are referring to (since there is no short hand way to specify the number of ? that should be checked like there is in regular expressions).
- Create your own composite
LineMapper
implementation that uses regular expressions to do the mapping.
记录下来,如果您选择选项2,请将其贡献回来!
For the record, if you choose option 2, contributing it back would be appreciated!
这篇关于如何使用PatternMatchingCompositeLineMapper在Spring批处理中实现复杂的模式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!