我正在尝试使用正则表达式根据以下字符串(回车符在字符串中)仅选择粗体(减去 *'s)。我想从中选择它的每个字符串都以 ISA 开头。我一直在尝试使用它 (?<=ISA\\*)(\w*) ,但是每当我开始添加要在 (?<...) 部分中排除的其他字符时,我就找不到任何匹配项。
ISA*00* *00* *ZZ*SOME STRING *ZZ*99999999 *130605* 2239*|*00501*000000001*0*P*>
REF*TJ*12345677*
REF*PQ*23432211
LX*1
请您参考如下方法:
以下应该有效:
^ISA(?:[^*]*[*][^*]*){8}\*(\d+)\*
参见 http://regex101.com/r/lU8sC8/1
它的工作方式:
^ISA — start of string has "ISA"
(?: — non-capturing group
[^*]*[*][^*]* — zero or more non-asterisks, followed by asterisk, followed by non-asterisk
{8} — eight of these
\* — one more asterisk
(\d+) — capture one or more digits
\* — followed by another asterisk
