Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    14 Posts 3 Posters 1.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.
    • Robin CruiseR Offline
      Robin Cruise
      last edited by

      @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
      • Terry RT Offline
        Terry R
        last edited by

        @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
        • Robin CruiseR Offline
          Robin Cruise
          last edited by

          @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
          • Robin CruiseR Offline
            Robin Cruise
            last edited by

            maybe I did something wrong…

            EkopalypseE Terry RT 2 Replies Last reply Reply Quote 0
            • EkopalypseE Offline
              Ekopalypse @Robin Cruise
              last edited by

              @Robin-Cruise

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

              Robin CruiseR 1 Reply Last reply Reply Quote 0
              • Terry RT Offline
                Terry R @Robin Cruise
                last edited by

                @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

                Robin CruiseR 1 Reply Last reply Reply Quote 1
                • Robin CruiseR Offline
                  Robin Cruise @Terry R
                  last edited by

                  @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…

                  Terry RT 1 Reply Last reply Reply Quote 0
                  • Robin CruiseR Offline
                    Robin Cruise @Ekopalypse
                    last edited by

                    @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?

                    EkopalypseE 1 Reply Last reply Reply Quote 0
                    • Terry RT Offline
                      Terry R @Robin Cruise
                      last edited by Terry R

                      @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
                      • EkopalypseE Offline
                        Ekopalypse @Robin Cruise
                        last edited by

                        @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

                        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