Community
    • Login

    RegEx problems

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    28 Posts 8 Posters 2.2k 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.
    • Thomas 2020T
      Thomas 2020
      last edited by Thomas 2020

      I want to find quotation marks:

      "
      

      Can I search for 0022 or (0x22) instead "
      e.g
      Schowek02.jpg

      that you understand some regex concepts

      I agree… some.
      I’ve been practicing for about 3 weeks

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Thomas 2020
        last edited by

        @Pan-Jan

        \x22

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

          @Pan-Jan said in RegEx problems:

          I have it like this:

          abc
          1
          2
          3
          

          It should look like this:

          abc 123
          
          • FIND = (?-s)^(.*)\R(.*)\R(.*)\R(.*)$
          • REPLACE = $1\x20$2$3$4
          Thomas 2020T 1 Reply Last reply Reply Quote 0
          • Thomas 2020T
            Thomas 2020 @PeterJones
            last edited by

            @PeterJones

            ABC
            1
            2
            3
            4
            5
            
            ABC 12345
            

            ZNAJDŹ = (?-s)^(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)$
            REPLACE = $1\x20$2$3$4$5$6

            And when there are more than 5?

            PeterJonesP Terry RT 2 Replies Last reply Reply Quote 0
            • Thomas 2020T
              Thomas 2020 @Alan Kilborn
              last edited by

              @Alan-Kilborn
              Thanks
              in fact, I’ve seen \x20 many times but didn’t associate it.

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

                @Pan-Jan said in RegEx problems:

                And when there are more than 5?

                As far as I know, you have to keep on adding more groups.

                There may be some regex that would allow finding one line, followed by one or more lines; join with a space between the first two, and join without space on any additional lines. But I don’t know what it would be, and our resident regex magician is on holiday this month. But maybe one of the other gurus has some ideas.

                Thomas 2020T 1 Reply Last reply Reply Quote 0
                • Thomas 2020T
                  Thomas 2020 @PeterJones
                  last edited by Thomas 2020

                  @PeterJones
                  I tried ((.*)\R){6} instead (.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R
                  but nothing works.

                  1 Reply Last reply Reply Quote 0
                  • Terry RT
                    Terry R @Thomas 2020
                    last edited by

                    @Thomas-2020 said in RegEx problems:

                    And when there are more than 5?

                    Actually there is a regex which will work regardless of how many numbers appear on the following lines in 1 pass.
                    Using the Replace function we have:
                    Find What:(\w+$)|(\R(\d+))
                    Replace With:(?1\1\x20)(?2\3)

                    So by using “alternation” we either have a word line or a number line. Each is dealt with in a different manner. the word line is re-written with a following space (\x20) and the number line has the preceding line feed/carriage return removed.

                    There is a proviso though. As this just lumps the numbers together, once you get to 10, how do you identify each of the “separate” numbers in the group. See my example below.

                    ABC
                    1
                    2
                    3
                    4
                    5
                    ABC
                    1
                    2
                    3
                    4
                    5
                    6
                    7
                    8
                    9
                    10
                    11
                    ABC
                    1
                    2
                    3
                    ABC
                    1
                    2
                    3
                    4
                    5
                    6
                    7
                    8
                    9
                    10
                    11
                    12
                    

                    and now we have:

                    ABC 12345
                    ABC 1234567891011
                    ABC 123
                    ABC 123456789101112
                    

                    Not a pretty number sequence anymore!

                    Terry

                    1 Reply Last reply Reply Quote 3
                    • Pan JanP
                      Pan Jan
                      last edited by

                      Thanks, it works great.
                      I mainly learn from examples.
                      the written explanation after translation is usually “bla” “bla” “bla”
                      I have a request to show me a specific example,
                      when is it necessary to use this (?1)
                      So far, everything works without this pattern.
                      e.g
                      (?1\1)(?2\3) -> \1\3

                      PeterJonesP Terry RT 2 Replies Last reply Reply Quote 0
                      • PeterJonesP
                        PeterJones @Pan Jan
                        last edited by PeterJones

                        @Pan-Jan said in RegEx problems:

                        when is it necessary to use this (?1)

                        That is the “conditional replacement” notation, described at https://npp-user-manual.org/docs/searching/#substitution-conditionals

                        Basically, @Terry-R’s replacement regex says

                        • (?1\1\x20) = if group1 (the \w+$ subpattern) matched, then include the contents of group1 followed by a space in the replacement
                        • (?2\3) = if group2 (the newline followed by one or more digits) matched, then include the contents of group3 (just the digits from inside group2) in the replacement

                        Your replacement \1\3 will strip out the newlines, but it will not put a space after the abc and before the 123. If that’s okay with you (even though it violates the original), then your simpler regex will work. But @Terry-R’s regex actually matches the behavior you claimed you wanted.

                        1 Reply Last reply Reply Quote 0
                        • Pan JanP
                          Pan Jan
                          last edited by

                          Schowek01.jpg
                          Schowek02.jpg

                          1 Reply Last reply Reply Quote -1
                          • Alan KilbornA
                            Alan Kilborn
                            last edited by

                            Posting screenshots without text describing them isn’t going to get you very far.

                            I think we need to “draw the line” and put a stop to Community members using this forum as a means to “learn regular expressions”.

                            It isn’t what this site is for.

                            Sure, asking questions about the “peculiarities” of the N++ regex engine is certainly welcome here, as are general questions of “how to transform data” by noobs that may never even heard of the regular expression concept are also welcome.

                            But to blatantly use this site as a continual Q-and-A, back-and-forth discussion of common regex concepts is, well, annoying. There are far better places for that type of discussion.

                            1 Reply Last reply Reply Quote 2
                            • Pan JanP
                              Pan Jan
                              last edited by

                              This post is deleted!
                              1 Reply Last reply Reply Quote 0
                              • Pan JanP
                                Pan Jan
                                last edited by

                                Your replacement \1\3 will strip out the newlines, but it will not put a space after the abc and before the 123.
                                I showed there is a space between ABC and 123451012.

                                Sure, asking questions about the “peculiarities” of the N++ regex engine is certainly welcome here
                                I think we need to “draw the line” and put a stop to Community members using this forum as a means to “learn regular expressions”.
                                No comment

                                1 Reply Last reply Reply Quote -2
                                • guy038G
                                  guy038
                                  last edited by

                                  Hello, @pan-jan, @alan-kilborn, @peterjones and All,

                                  Two years ago, about, I said :

                                  By answering, for the most part, to questions, related to regular expressions, ( for years ! ), am I distorting the true purpose of this forum, which should remain, I agree, focused on the features, improvements and bugs of Notepad++ ?

                                  Refer to :

                                  https://notepad-plus-plus.org/community/topic/16509/regex-select-all-from-row-except/16


                                  So, I totally agree with Alan’s assertion ! There are plenty of sites, devoted to regex’s learning :-)) So, @pan-jan, just have a look to this FAQ :

                                  https://notepad-plus-plus.org/community/topic/15765/faq-desk-where-to-find-regex-documentation/1

                                  To my mind, one needs 2 weeks, about, to get the basics of regular expressions and, let’s say, between 1 to 3 months to fully understand all the subtleties of this pseudo-language ;-))

                                  Cheers,

                                  guy038

                                  1 Reply Last reply Reply Quote 3
                                  • Pan JanP
                                    Pan Jan
                                    last edited by Pan Jan

                                    I wrote above that reading texts in a foreign language in such matters does not make sense.
                                    I know Polish and German.

                                    For me, what matters is a specific answer.
                                    Then I will analyze and verify it.
                                    If it’s okay, I’ll try to remember it.

                                    For me, the lack of a specific answer means that my version is correct.
                                    Simple logic.

                                    it works:
                                    Replace With:(?1\1\x20)(?2\3)

                                    correct:
                                    Replace With:\1\3

                                    Cheers, Thomas 2020.

                                    Chers translated into Polish means the same as: “Your health”
                                    This is what people say when they toast with a glass of vodka in their hands.

                                    Unfortunately, that’s how translators work.
                                    Maybe in 20 years it will be better.

                                    EkopalypseE 1 Reply Last reply Reply Quote 0
                                    • EkopalypseE
                                      Ekopalypse @Pan Jan
                                      last edited by

                                      @Pan-Jan

                                      Ok, überzeuge mich das ich es nicht mit einem Troll zu tun habe.
                                      Was ist die Frage, was hast Du gemacht, was war das Resultat und
                                      was hättest Du erwartet?

                                      Übrigens, cheers bedeutet im englischen auch Prost,
                                      wird aber auch als Grußwort benutzt.

                                      Ok, convince me I’m not dealing with a troll.
                                      What is the question, what did you do, what was the result and
                                      what did you expect?

                                      By the way, cheers in English means Prost,
                                      but is also used as a greeting word.

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

                                        @Ekopalypse ,

                                        I don’t know that you needed to bother in this one; he seems to think he has a working expression, from what I can tell.

                                        1 Reply Last reply Reply Quote 1
                                        • Pan JanP
                                          Pan Jan
                                          last edited by Pan Jan

                                          This post is deleted!
                                          1 Reply Last reply Reply Quote 0
                                          • Pan JanP
                                            Pan Jan
                                            last edited by

                                            @PeterJones
                                            Replace With:(?1\1\x20)(?2\3)

                                            You wrote it (?1 and (?2?. In general, I asked for an example where without this (?1` formula will not work.

                                            I counted most on @guy038.
                                            Instead, he sends me elsewhere for a reply.

                                            It cannot write that this (?1 or (?2 is redundant.

                                            So far I think (?1 or (?2 is redundant at all.

                                            I’m not questioning anyone’s knowledge, but I want to understand it through examples.

                                            And since I have my opinion, I’m definitely a Russian troll.
                                            Thomas2020.jpg

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