【发布时间】:2020-09-02 12:49:46
【问题描述】:
sample_string = ":61:2002190219C45612.4S202EXC:OL3654628815//CT56748005:86:/BENM/Unitech Imports/REM//58970.047:61:2002190219C30000S103LCADV5674920204//CT56748006:86:/BENM/Gravity Imports/REM//INV:/FEB20/446301:61:2002190219C45612.4S202EXCOL3654628825//CT56748005:60F:61:2002190219C45612.4S202EXCOL3654628815//CT56748018"
基本上我都需要
1. :61:, :86: string which are next to each other any where in the full message ex:- re.findall()=expected o/p - [':61:2002190219C45612.4S202EXC:OL3654628815//CT56748005:86:/BENM/Unitech Imports/REM//58970.047', :61:2002190219C30000S103LCADV5674920204//CT56748006:86:/BENM/Gravity Imports/REM//INV:/FEB20/446301]
i have below regex for above case which is working fine, can we simplify a bit,
61:(?:[\w /,.-]|:(?!61:|86:))*:86:(?:[A-Za-z0-9 /.-]|:(?!61:|86:))*
regex example - https://regex101.com/r/U3MWF7/4
2. All :61 string which are not followed by :86 anywhere in the full message, ex:- re.findall()=
expected o/p=[':61:2002190219C45612.4S202EXCOL3654628825//CT56748005',':61:2002190219C45612.4S202EXCOL3654628815//CT56748018']
I have below regex to get all :61 strings from message which is not giving correct result - its giving all :61 strings which are followed by:86 also.
61:(?:[\w /,.-]|:(?!61:|86:))*(?!:86:)* ()
regex example - https://regex101.com/r/2svNjG/1
我尝试了多个选项,但无法获得所需的输出。寻求帮助
【问题讨论】:
-
喜欢这个?
:61:(?!.*:86).*?(?=:61:|$)regex101.com/r/zA9SFB/1和regex101.com/r/iieEyg/1