Community
    • Login

    finding a partial number with Wildcard

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 4 Posters 872 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Darren WartnabyD Offline
      Darren Wartnaby
      last edited by

      Hi i have an XML file with multiple account number and i want to Find in the Tag <AccNbr> all lines that have 222 as any part of the number how would I search

      <AcctNbr>111111222</AcctNbr>

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA Online
        Alan Kilborn @Darren Wartnaby
        last edited by

        @Darren-Wartnaby

        Try:

        Find: (?-s)<AcctNbr>.*?222.*?</AcctNbr>
        Search mode: Regular expression

        mkupperM 1 Reply Last reply Reply Quote 3
        • mkupperM Offline
          mkupper @Alan Kilborn
          last edited by

          @Alan-Kilborn said in finding a partial number with Wildcard:

          Find: (?-s)<AcctNbr>.*?222.*?</AcctNbr>
          Search mode: Regular expression

          I would lean towards using (?-i)<AcctNbr>\d*222\d*</AcctNbr>
          XML is case sensitive which is why I use (?-i).
          It’s a number and so I use \d* instead of .*? which allows any character. As I don’t use the dot (.) operator I don’t need the (?-s) nor the ? non-greedy modifier.

          @Darren-Wartnaby - A web page that explains the various things shown here is at https://npp-user-manual.org/docs/searching/#regular-expressions

          Alan’s version is better if there is a chance that whatever is between <AcctNbr> and </AcctNbr> has things other other than numeric digits at times.

          1 Reply Last reply Reply Quote 2
          • Darren WartnabyD Offline
            Darren Wartnaby
            last edited by

            @Alan-Kilborn said in finding a partial number with Wildcard:

            *?222

            Alan thanks so if I want to search for two number in that one string do i repeat this part .*?222.

            Alan KilbornA 1 Reply Last reply Reply Quote 0
            • Alan KilbornA Online
              Alan Kilborn @Darren Wartnaby
              last edited by

              @Darren-Wartnaby said in finding a partial number with Wildcard:

              so if I want to search for two number in that one string do i repeat this part .*?222

              You could, but there are some issues with ordering; i.e., you would only find matches in the left-to-right order of the two numbers specified.

              1 Reply Last reply Reply Quote 2
              • Mark OlsonM Offline
                Mark Olson
                last edited by Mark Olson

                Suppose you want to find text in AcctNbr tags containing the numbers 48, 17, and 34 in any order. You could enumerate every possible ordering of those numbers, but that would become increasingly intractable as the number of things to be matched got larger (e.g., there are 24 possible orderings of four distinct things). This is where forward lookahead really shines.

                (?-si)<AcctNbr>(?=(?:(?!</AcctNbr>).)*?17)(?=(?:(?!</AcctNbr>).)*?34)(?=(?:(?!</AcctNbr>).)*?48).*?</AcctNbr>

                Try that out on the below text to see what I mean.

                <AcctNbr>1 2 3 4</AcctNbr>
                <AcctNbr>1 2 23 14</AcctNbr>
                <AcctNbr>27</AcctNbr>
                <AcctNbr>1234</AcctNbr>
                <AcctNbr>34 18</AcctNbr>
                <AcctNbr>48734</AcctNbr>
                <FooNbr>34 17 48</FooNbr>
                <!-- last three should match -->
                <AcctNbr>34 17 48</AcctNbr>
                <AcctNbr>4817 34</AcctNbr>
                <AcctNbr>483417</AcctNbr>
                

                NOTE: this method allows overlap between things to be matched, e.g., 348 would count for both 34 and 48. There is no efficient way to do this without making the regex much nastier.

                1 Reply Last reply Reply Quote 2

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors