Community
    • Login

    Very long pattern

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    21 Posts 4 Posters 5.0k Views
    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.
    • Olivier ThomasO
      Olivier Thomas
      last edited by

      I would like to find these numbers in the text,
      only the pattern will be a little too long.

      Find What:
      [5-9]|[10-21]|[25-31]|[35-41]|[45-51]|[55-61]|[65-71]|[75-81]|[85-91]|[95-101]|
      [105-109]|[110-121]|[125-131]|[135-141]|[145-151]|[155-161]|[165-171]|[175-181]|[185-191]|[195-201]|
      [205-209]|[210-221]|[225-231]|[235-241]|[245-251]|[255-261]|[265-271]|[275-281]|[285-291]|[295-301]|
      [305-309]|[310-321]|[325-331]|[335-341]|[345-351]|[355-361]|[365-371]|[375-381]|[385-391]|[395-401]|
      [405-409]|[410-421]|[425-431]|[435-441]|[445-451]|[455-461]|[465-471]|[475-481]|[485-491]|[495-501]

      Can it be shortened?

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Olivier Thomas
        last edited by

        @Olivier-Thomas ,

        Thanks for showing what you tried.

        Did you notice if you tried just one of those sub-expressions, it doesn’t do what you think?

        ac065fed-78a9-4b89-b2dd-9ea7b29a95e1-image.png

        [25-31] does not match any number from 25 to 31. It matches any character 2, 5-3, or 1. Since 5-3 is an invalid range, the whole regex is invalid.

        Assuming the exact ranges you specified, I tried

        • \b([1-4]?\d{0,1}[5-9]|[1-4]?\d[01]|50[01])\b
          f3db206a-1367-4c40-a7b3-0199c726a229-image.png
          Quick explanation:
        • I assumed that your example regex was exhaustive: that you didn’t want any numbers bigger than 501 to be matched
        • the \b are “boundaries”, so it won’t catch the numbers if they are part of bigger numbers (ie, not find the 499 in 34993)
        • [1-4]? allows the first digit to be a 1,2,3, or 4 for a 3-digit match
        • \d{0,1} matches 0 or 1 instance of any digit
        • Combining things, the left side of the alternate [1-4]?\d{0,1}[5-9] will find 5-9, 15-19, 25-29, … 95-99, 105-109, … 405-409, …, 495-499, but not 505-509.
        • The middle alternate [1-4]?\d[01] will find 10, 11, 20, 21, 30,31, …, 100,101, … 191, … 491, but not 511 or 591
        • The right alternate 50[01] handles the edge case because 500 and 501 break the other rules.

        If you were really trying to imply you wanted any number greater than 1 that ends in 0, 1, 5-9, then use

        • (\d*[5-9]|\d+[01])\b
          a9d00775-e698-4fbb-ab11-91c72d45579d-image.png

        which says match 0 or more digits followed by 5-9 and the boundary, or match one or more digits followed by 0-1 and the boundary.

        1 Reply Last reply Reply Quote 2
        • Olivier ThomasO
          Olivier Thomas
          last edited by

          @PeterJones said in Very long pattern:

          (\d*[5-9]|\d+[01])\b

          Thanks
          Works very well.
          The greater the range, the better.
          This one works up to a thousand and such a pattern is enough for me

          Missing only:
          12, 14, 112, 114

          1 Reply Last reply Reply Quote 0
          • Olivier ThomasO
            Olivier Thomas
            last edited by

            [10-21] [110-121] is not a formula, but a range of numbers
            from 10 to 21 and from 110 to 121

            Missing only:
            12, 14, 112, 114, 212, 214, 312, 314 e.t.c.

            1 Reply Last reply Reply Quote 0
            • Olivier ThomasO
              Olivier Thomas
              last edited by Olivier Thomas

              Missing only:
              12, 13, 14, 112, 113, 114, 212, 213, 214, 312, 313, 314 e.t.c.

              PeterJonesP 1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @Olivier Thomas
                last edited by

                @Olivier-Thomas

                I am assuming that these are just clarifying your simplification of your problem statement, and that you still have the solution you need. If this is not the case, please clarify, giving examples of numbers that are not properly matching.

                ----

                Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as plain text using the </> toolbar button or manual Markdown syntax. Screenshots can be pasted from the clipbpard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get… Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

                1 Reply Last reply Reply Quote 0
                • Olivier ThomasO
                  Olivier Thomas
                  last edited by

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • Olivier ThomasO
                    Olivier Thomas
                    last edited by

                    So I will write again.

                    Missing | does not find | do not appear
                    these numbers
                    12, 13, 14, 112, 113, 114, 212, 213, 214, 312, 313, 314 e.t.c.
                    Schowek01.jpg

                    astrosofistaA 1 Reply Last reply Reply Quote 0
                    • astrosofistaA
                      astrosofista @Olivier Thomas
                      last edited by

                      Hi @Olivier-Thomas, @PeterJones :

                      Then try this one instead —just adding a clause to @PeterJones’ expression—:

                      Find: ((\d*[5-9]|\d+[01])\b)|([1-9]?1[2-4]\b)

                      Seems to match all the required numbers.

                      Have fun!

                      PeterJonesP 1 Reply Last reply Reply Quote 2
                      • PeterJonesP
                        PeterJones @astrosofista
                        last edited by PeterJones

                        @astrosofista , thanks for that. In the 50 invalid character classes in the original group, I didn’t notice that 10-21 was different than all the other groups.

                        I would simplify yours (\d*[5-9]|\d+[01]|\d*1[2-4])\b

                        @Olivier-Thomas ,

                        You seem to be pasting a screenshot from some tool other than Notepad++. I don’t recognize it as coming from any Notepad++ plugin I’ve seen before: is it a Notepad++ plugin?

                        For your information, this forum is for Notepad++, NOT a generic regex help forum. If you abuse this forum as a generic “make regexes for me, no matter what tool I use”, you will quickly wear out your welcome here. If all you ever talk about is asking for us to make regexes for you, you will wear out your welcome here. This behavior is similar to the behavior condemned in the user @Thomas-2020 / @Pan-Jan , whose thread you recently replied to; learn the lesson from that user and don’t behave like him. (If your behavior starts looking like that user, we will assume you are the same user with a third account, respond accordingly.)

                        If you are here to talk about Notepad++, great. If not, you might want to find a generic regex help forum.

                        1 Reply Last reply Reply Quote 4
                        • Olivier ThomasO
                          Olivier Thomas
                          last edited by

                          from ## to ##
                          [2-4] [22-24] [32-34] [42-44] [52-54] … [92-94] [102-104] [122-124] [132-134] … [202-204] [222-224] [232-234] …

                          I made such a pattern
                          (\d*[2-9]|(\d+0)*)[2-4]
                          what would you improve on this?

                          PeterJonesP 1 Reply Last reply Reply Quote -1
                          • PeterJonesP
                            PeterJones @Olivier Thomas
                            last edited by

                            @Olivier-Thomas ,

                            If it works for you, use it. We have given you enough that you can accomplish this task.

                            We have pointed you to the official regex documentation for Notepad++, and the FAQ in this forum gives lots of other sites that have other regex help.

                            You seem to have enough regex experience to be able to delve into other regex syntax yourself.

                            This is not a generic regex help desk. And this is especially not a we-write-all-your-regex-for-you forum.

                            1 Reply Last reply Reply Quote 1
                            • Olivier ThomasO
                              Olivier Thomas
                              last edited by Olivier Thomas

                              Do you read what you write or do you think about it for a moment?
                              For your information, this forum is for Notepad++, NOT a generic regex help forum.

                              Is it prohibited to use Notepad to search for numbers in the text?
                              You don’t answer the questions yourself.

                              what would you improve on this?

                              Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote -5
                              • Alan KilbornA
                                Alan Kilborn @Olivier Thomas
                                last edited by

                                @Olivier-Thomas

                                Oh, boy…here we go…

                                1 Reply Last reply Reply Quote 1
                                • PeterJonesP
                                  PeterJones @Olivier Thomas
                                  last edited by PeterJones

                                  @Olivier-Thomas ,

                                  You are behaving exactly like @Pan-Jan (PJ) and @Thomas-2020 (T2) , and I am working from the assumption that you are, in fact, that individual.

                                  Is it prohibited to use Notepad to search for numbers in the text?

                                  No. But it’s rude to not try things yourself, first. And it’s rude to abuse this forum to make us do your work for you.

                                  You don’t answer the questions yourself.

                                  Stop lying. I have given you and PJ and T2 so many answers it’s ridiculous.

                                  what would you improve on this?

                                  If it worked for me, I would do nothing to improve on it. If it didn’t work for me, I would debug it until it did.

                                  As with PJ and T2, I will not answer any more questions from @Olivier-Thomas until such time as he proves that he is willing to be a contributing , cooperative, non-demanding member of the community rather than an annoying vampire

                                  1 Reply Last reply Reply Quote 3
                                  • Olivier ThomasO
                                    Olivier Thomas
                                    last edited by Olivier Thomas

                                    But it’s rude to not try things yourself, first
                                    Where do you get that confidence?

                                    I wrote the pattern.
                                    I asked what would you change?
                                    You did not answer.

                                    Here nobody asked you and you corrected the pattern.

                                    @astrosofista , thanks for that. In the 50 invalid character classes in the original group,
                                    I didn’t notice that 10-21 was different than all the other groups.

                                    I would simplify yours (\d*[5-9]|\d+[01]|\d*1[2-4])\b*

                                    I don’t think you like people outside your clan.

                                    PeterJonesP 1 Reply Last reply Reply Quote -3
                                    • PeterJonesP
                                      PeterJones @Olivier Thomas
                                      last edited by PeterJones

                                      @Olivier-Thomas said in Very long pattern:

                                      I asked what would you change?
                                      You did not answer.

                                      The first time you asked, I told you to use what you had if it worked. The second time, I told you I would not change anything. I did answer.

                                      Here nobody asked you and you corrected the pattern.

                                      I didn’t correct it. I simplified it. As part of the flow of conversation. And I am sure @astrosofista was not upset that I did so. And if I did upset him, he is quite capable of letting me know.

                                      I don’t think you like people outside your clan.

                                      Wow! Ad hominem attacks are frowned upon (and usually forbidden) in every forum I’ve been a part of.

                                      What I don’t like is behavior like yours or T2 or PJ, who come here, ask us to write their regexes for them, then change the rules and ask us to rewrite them, and keep doing that, and who treat this forum like their personal regex writing tool.

                                      If the regex works for you, use it. If it doesn’t, debug it. If you have questions that are specific to Notepad++'s implementation, ask away. If you want generic regex help, find a regex forum (this isn’t it).

                                      astrosofistaA 1 Reply Last reply Reply Quote 2
                                      • Olivier ThomasO
                                        Olivier Thomas
                                        last edited by

                                        @PeterJones said in Very long pattern:

                                        vampire

                                        Why are you provoking?
                                        Do you want to show I’m a vampire or a troll?
                                        You sit in the virtual world too much (possibly playing) and start to lose touch with the real world.
                                        I am not a priest, but I believe people should be brothers, not enemies.
                                        Think about it before it’s too late.

                                        PeterJonesP 1 Reply Last reply Reply Quote -1
                                        • PeterJonesP
                                          PeterJones @Olivier Thomas
                                          last edited by

                                          @Olivier-Thomas ,

                                          I am sorry I overreacted; I am sorry if I offended, though that was not my intention. I did my best to provide answers to your questions as long as I thought they were still relevant to Notepad++. When you posted a screenshot of a tool that didn’t appear to be Notepad++, I called you out on it, because we aren’t here for generic regex questions.

                                          We recently had another user who was asking regex questions, and then complaining that those didn’t work in some non-Notepad++ tool and demanding that we re-write them in alternate syntax that would work in the non-Notepad++ tool. I was getting the impression that you were trying to do the same, so my frustration came through. For that, I am sorry.

                                          Back to our regularly-scheduled Notepad++ discussion.

                                          1 Reply Last reply Reply Quote 2
                                          • astrosofistaA
                                            astrosofista @PeterJones
                                            last edited by

                                            @PeterJones said in Very long pattern:

                                            I didn’t correct it. I simplified it. As part of the flow of conversation. And I am sure @astrosofista was not upset that I did so. And if I did upset him, he is quite capable of letting me know.

                                            Hi @PeterJones,

                                            Of course, I’m not upset at all, even I upvoted your contribution, which as mine I think it was a collaborative effort to improve the responses that each one, individually, can offer.

                                            Have fun!

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors