• Login
Community
  • Login

regular expression - why don't the last words change their order?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
14 Posts 3 Posters 599 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.
  • T
    Terry R @Robin Cruise
    last edited by Terry R Apr 3, 2020, 5:47 AM Apr 3, 2020, 5:47 AM

    @Robin-Cruise said in regular expression - why don't the last words change their order?:

    the last 4-5 words do not change their position. Why ?

    Your regex has 1 or more horizontal spaces behind every word. In your example the 15th word does not have a space behind, rather a ‘.’. Therefore the regex will not do those 5 words.

    Terry

    1 Reply Last reply Reply Quote 1
    • R
      Robin Cruise
      last edited by Robin Cruise Apr 3, 2020, 6:57 AM Apr 3, 2020, 6:56 AM

      @Terry-R said in regular expression - why don't the last words change their order?:

      Your regex has 1 or more horizontal spaces behind every word. In your example the 15th word does not have a space behind, rather a ‘.’. Therefore the regex will not do those 5 words.

      good day, @Terry-R I do not understand. Can you give me a response formulated in regex, a good solution? Because I don’t think it has to do with space or '.

      1 Reply Last reply Reply Quote 0
      • T
        Terry R
        last edited by Apr 3, 2020, 7:16 AM

        How about reading up on the special codes such as \h to know what they cover. For example try
        http://rexegg.com/regex-quickstart.html
        As well as documentation as provided in the FAQ section.

        I’m not on my PC but I’d suggest removing that last \h+ in your regex. Although you are using the regex in a replace function you can see what it will capture or not by using the find button and seeing each group it does capture one at a time. Just move the replace window so it doesn’t cover the data, that’s the way I test.

        Terry

        1 Reply Last reply Reply Quote 2
        • R
          Robin Cruise
          last edited by Apr 3, 2020, 8:06 AM

          @Robin-Cruise said in regular expression - why don't the last words change their order?:

          (\w+)\h+(\w+)\h+(\w+)\h+(\w+)\h+(\w+)\h+

          yes, you right. Maybe I should use +.*? or just .*? instead of \h+

          1 Reply Last reply Reply Quote 0
          • T
            Terry R
            last edited by Apr 3, 2020, 8:16 AM

            @Robin-Cruise said in regular expression - why don't the last words change their order?:

            Maybe I should use +.? or just .?

            I would remove that last \h+ as your replacement text is not putting anything back behind that 5th word. By removing it the space or period characters would remain, thus only the words would change order, nothing else would be affected.

            Terry

            1 Reply Last reply Reply Quote 1
            • R
              Robin Cruise
              last edited by Apr 3, 2020, 8:26 AM

              @Terry-R said in regular expression - why don't the last words change their order?:

              I would remove that last \h+ as your replacement text is not putting anything back behind that 5th word. By removing it the space or period characters would remain, thus only the words would change order, nothing else would be affected.

              I change a little simple:

              SEARCH: (\w+) (\w+) (\w+) (\w+) (\w+)

              REPLACE BY: \5 \1 \4 \2 \3

              WORKS. The single problem, is that the last words doen not change in place of the first words… only after the 10 word…

              1 Reply Last reply Reply Quote 0
              • R
                Robin Cruise
                last edited by Apr 4, 2020, 11:31 AM

                maybe I did something wrong…

                E T 2 Replies Last reply Apr 4, 2020, 7:48 PM Reply Quote 0
                • E
                  Ekopalypse @Robin Cruise
                  last edited by Apr 4, 2020, 7:48 PM

                  @Robin-Cruise

                  then your data is different to what you think it is.
                  Did you double check by making all symbols visible?

                  R 1 Reply Last reply Apr 5, 2020, 5:03 AM Reply Quote 0
                  • T
                    Terry R @Robin Cruise
                    last edited by Apr 4, 2020, 10:02 PM

                    @Robin-Cruise said in regular expression - why don't the last words change their order?:

                    maybe I did something wrong…

                    I’m thinking you did. My LAST suggestion was to JUST remove that last \h+ as your regex was working on all other groups excluding one’s with . instead of 1 or more horizontal spaces.

                    Did you try that at all?!

                    Terry

                    R 1 Reply Last reply Apr 5, 2020, 5:01 AM Reply Quote 1
                    • R
                      Robin Cruise @Terry R
                      last edited by Apr 5, 2020, 5:01 AM

                      @Terry-R said in regular expression - why don't the last words change their order?:

                      @Robin-Cruise said in regular expression - why don't the last words change their order?:

                      maybe I did something wrong…
                      

                      I’m thinking you did. My LAST suggestion was to JUST remove that last \h+ as your regex was working on all other groups excluding one’s with . instead of 1 or more horizontal spaces.

                      Did you try that at all?!

                      Terry

                      yes, but the same thing, this will change the 5 words after the first ten words. But if I want word15 to be in the place of word1, will not work…

                      T 1 Reply Last reply Apr 5, 2020, 6:55 AM Reply Quote 0
                      • R
                        Robin Cruise @Ekopalypse
                        last edited by Apr 5, 2020, 5:03 AM

                        @Ekopalypse said in regular expression - why don't the last words change their order?:

                        @Robin-Cruise

                        then your data is different to what you think it is.
                        Did you double check by making all symbols visible?

                        hi. how can I do this?

                        E 1 Reply Last reply Apr 5, 2020, 9:55 AM Reply Quote 0
                        • T
                          Terry R @Robin Cruise
                          last edited by Terry R Apr 5, 2020, 6:57 AM Apr 5, 2020, 6:55 AM

                          @Robin-Cruise said in regular expression - why don't the last words change their order?:

                          But if I want word15 to be in the place of word1, will not work…

                          This appears to be a change in requirement. Your 1 example had 15 words and your regex was working with 5 words at a time, so your example would deal with the first 5 words, then the second set of 5 words. It failed on the third set of 5 words as it had the \h+.

                          In that example with the \h+ missing it should deal with ALL 3 sets of 5 words, one set at a time. Now however your reply that I copied above suggests you want the set of 15 words dealt with as 1 set.

                          I’m going to give you the benefit of doubt as it also seems that English is not your primary language. So instead of giving yet more solutions to a possibly changing requirements I need you to tell us exactly what you require. I also need you to give more examples, showing both before and after processing views.

                          If you do not provide that additional information I’m opting out of this!

                          1 Reply Last reply Reply Quote 4
                          • E
                            Ekopalypse @Robin Cruise
                            last edited by Apr 5, 2020, 9:55 AM

                            @Robin-Cruise

                            View->Show Symbol->Show All Characters

                            But as @Terry-R wrote, it seems that you are changing your requirements and this is something that does not work well with regexes.

                            If there is a language barrier here, try using an online translator and posting in your native language and the translated English version.

                            What I have written here was translated with DeepL.com

                            1 Reply Last reply Reply Quote 2
                            11 out of 14
                            • First post
                              11/14
                              Last post
                            The Community of users of the Notepad++ text editor.
                            Powered by NodeBB | Contributors