Java 字符串中多个字符串模式的正则表达式
Java regex for multiple string pattern in a string
您好,我需要验证字符串中是否包含按 java
中的顺序排列的几个强制性单词
ISA*00* *00* *ZZ*FEDX *08*123243432 *200905*0616*^*00501*1231231*0*P*:!GS*MZ*FEDX*123243432*20200905*0616*18859*X*005010!ST*240*188590001!BGN*00*123432423423234*20200905*061625**136634142!N1*SH*HUNTER FAN!N3*100 NEMAC WAY!N4*BYHALIA*MS*38611*US!LX*1!N1*CN*TEST S COMPANIES INC.!N3*201 WASHINGTON STREET!N4*123123*MA*123123*US!L11*123432423423234*2I!LS*2710!MAN*CP*OD*SEEKONK*CP*ASA*US!L11*1231231*OQ!AT7*AM*BG***20200905*0654*LT!AT7*AG*BG***20200905*0000*LT!CD3*L*26.1!LE*2710!SE*18*12312312!ST*240*188590002!BGN*00*123123123*20200905*061625**150139758!N1*SH*HUNTER FAN!N3*100 NEMAC WAY!N4*1231231*MS*38611*US!LX*1!N1*CN*TEST S COMPANIES INC.!N3*850 ROUTE 44!N4*ASDSDS*MA*02767*US!L11*1231231*2I!LS*2710!MAN*CP*FD*ASASAS*CP*ASAS*US!L11*12312312*OQ!AT7*X5*BG***20200905*0649*LT!AT7*AG*BG***20200905*0000*LT!CD3*L*24.2!LE*2710!SE*18*188590002!GE*2278*18859!IEA*1*000002724!
我想检查上面的字符串是否按顺序包含某些字符串(下面列出)(数据中有 *),寻找正则表达式
ISA* , !GS* , !ST* ,!BGN* ,!LX* ,!L11* , !LE* ,!GE* ,!IEA*
'^(ISA\*)+(!GS\*)+(!ST\*)*'
我试过上面的方法,但没有用。
试过这个link
https://www.freeformatter.com/java-regex-tester.html
使用
^ISA\*.*!GS\*.*!ST\*.*
说明
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
ISA 'ISA'
--------------------------------------------------------------------------------
\* '*'
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
!GS '!GS'
--------------------------------------------------------------------------------
\* '*'
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
!ST '!ST'
--------------------------------------------------------------------------------
\* '*'
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
您好,我需要验证字符串中是否包含按 java
中的顺序排列的几个强制性单词ISA*00* *00* *ZZ*FEDX *08*123243432 *200905*0616*^*00501*1231231*0*P*:!GS*MZ*FEDX*123243432*20200905*0616*18859*X*005010!ST*240*188590001!BGN*00*123432423423234*20200905*061625**136634142!N1*SH*HUNTER FAN!N3*100 NEMAC WAY!N4*BYHALIA*MS*38611*US!LX*1!N1*CN*TEST S COMPANIES INC.!N3*201 WASHINGTON STREET!N4*123123*MA*123123*US!L11*123432423423234*2I!LS*2710!MAN*CP*OD*SEEKONK*CP*ASA*US!L11*1231231*OQ!AT7*AM*BG***20200905*0654*LT!AT7*AG*BG***20200905*0000*LT!CD3*L*26.1!LE*2710!SE*18*12312312!ST*240*188590002!BGN*00*123123123*20200905*061625**150139758!N1*SH*HUNTER FAN!N3*100 NEMAC WAY!N4*1231231*MS*38611*US!LX*1!N1*CN*TEST S COMPANIES INC.!N3*850 ROUTE 44!N4*ASDSDS*MA*02767*US!L11*1231231*2I!LS*2710!MAN*CP*FD*ASASAS*CP*ASAS*US!L11*12312312*OQ!AT7*X5*BG***20200905*0649*LT!AT7*AG*BG***20200905*0000*LT!CD3*L*24.2!LE*2710!SE*18*188590002!GE*2278*18859!IEA*1*000002724!
我想检查上面的字符串是否按顺序包含某些字符串(下面列出)(数据中有 *),寻找正则表达式
ISA* , !GS* , !ST* ,!BGN* ,!LX* ,!L11* , !LE* ,!GE* ,!IEA*
'^(ISA\*)+(!GS\*)+(!ST\*)*'
我试过上面的方法,但没有用。
试过这个link https://www.freeformatter.com/java-regex-tester.html
使用
^ISA\*.*!GS\*.*!ST\*.*
说明
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
ISA 'ISA'
--------------------------------------------------------------------------------
\* '*'
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
!GS '!GS'
--------------------------------------------------------------------------------
\* '*'
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
!ST '!ST'
--------------------------------------------------------------------------------
\* '*'
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))