-1

I have beneficiaries that may or may not exist on multiple lines. How can I match <Beneficiaries and ignore the lines inside that element? I can only regex when I know the exact number of lines. I want to be able to skip the lines since the number of beneficiaries is always different and match the bottom portion. The goal is to combine this with another regex if possible.

<Beneficiaries />
            <PlanMapping />
            <EnrollmentMapping>
<Beneficiaries>
            <Beneficiary>
              <Benefit>Life</Benefit>
              <BenefitRelationship>Spouse</BenefitRelationship>
              <DOB>1235-12-12T00:00:00</DOB>
              <Primary>true</Primary>
              <Person>true</Person>
              <FirstName>john</FirstName>
              <MiddleName />
              <LastName>doe</LastName>
              <SSN />
              <PercentShare>100.00</PercentShare>
            <PlanMapping />
            <EnrollmentMapping>
<EnrollmentMapping>
            <EnrollmentLocationCode>
              <Value>01000008-StackOverflow</Value>
            </EnrollmentLocationCode>
          </EnrollmentMapping>
          <PlanIdentifier>b4354773-bc6e-41e1-64ad-46abd4c35547</PlanIdentifier>
          <MaintenanceCodeDate xsi:nil="true" />

Regex pattern

Beneficiaries(?=.*01000008)  

https://regex101.com/r/Wce8Kn/2

Non-regex solution: I duplicated the file, ran one regex and another to compare side-by-side. It reduced the number of matches from 107 to 5.

imparante
  • 494
  • 8
  • 18
  • What do you want to match in that sample above? – Wiktor Stribiżew May 18 '22 at 17:26
  • 1
    this looks like a follow-up to your previous Question https://stackoverflow.com/questions/72233887/regex-to-search-for-unique-last-names-in-xml .. as suggested, try using an XML parser, it will not have these sorts of problems - see the specific Answer https://stackoverflow.com/a/1758162/4541045 – ti7 May 18 '22 at 17:28
  • I am trying to match the bottom xml with the unique identifier and check other things above beneficiaries with a regex that works. The beneficiaries section is dynamic and I am unable to create a regex pattern that can skip through it. – imparante May 18 '22 at 18:49

0 Answers0