英文:
Java regex for multiple string pattern in a string
问题
hi我需要在Java中验证字符串是否按顺序包含其中的一些必需单词
ISA* ,!GS* ,!ST* ,!BGN* ,!LX* ,!L11* ,!LE* ,!GE* ,!IEA*
'^(ISA*)+(!GS*)+(!ST*)*'
我尝试了上面的方法,但没有成功。
在此链接中尝试过
https://www.freeformatter.com/java-regex-tester.html
英文:
hi I need to validate if the string is having few mandatory words in it in an order in 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!
i wanted to check if the above string is having certain strings ( listed below ) in order ( the data has * in it ) , looking for a regex
ISA* , !GS* , !ST* ,!BGN* ,!LX* ,!L11* , !LE* ,!GE* ,!IEA*
'^(ISA\*)+(!GS\*)+(!ST\*)*'
I tried the above but it didn't work .
Tried in this link
https://www.freeformatter.com/java-regex-tester.html
答案1
得分: 1
使用
^ISA\*.*!GS\*.*!ST\*.*
查看证明
解释
--------------------------------------------------------------------------------
^ 字符串的开头
--------------------------------------------------------------------------------
ISA 'ISA'
--------------------------------------------------------------------------------
\* '*'
--------------------------------------------------------------------------------
.* 除了 \n 之外的任意字符(0 次或多次
(匹配尽可能多的次数))
--------------------------------------------------------------------------------
!GS '!GS'
--------------------------------------------------------------------------------
\* '*'
--------------------------------------------------------------------------------
.* 除了 \n 之外的任意字符(0 次或多次
(匹配尽可能多的次数))
--------------------------------------------------------------------------------
!ST '!ST'
--------------------------------------------------------------------------------
\* '*'
--------------------------------------------------------------------------------
.* 除了 \n 之外的任意字符(0 次或多次
(匹配尽可能多的次数))
英文:
Use
^ISA\*.*!GS\*.*!ST\*.*
See proof
Explanation
--------------------------------------------------------------------------------
^ 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))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论