Community
    • Login

    move * before

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    13 Posts 3 Posters 3.5k 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.
    • Pouemes44P
      Pouemes44
      last edited by

      hello all
      i have a lot of lines like this
      <a href=“url/myurl.htm”>* name</a>
      i would as result to get

      • <a href=“url/myurl.htm”>name</a>

      so to put the * before <a

      i dont succeed to make a regex
      thanks

      Claudia FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @Pouemes44
        last edited by

        @Pouemes44

        from the data provided I would assume this should do the trick

        find what:(<a.*?>)(\*\x20)(.*?<\/a>)
        replace with:* $1$3
        

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 0
        • Pouemes44P
          Pouemes44
          last edited by

          @Claudia-Frank said:

          • $1$3

          wahoo a great thanks claudia, it works
          can you explain me how it works

          Claudia FrankC 1 Reply Last reply Reply Quote 0
          • Claudia FrankC
            Claudia Frank @Pouemes44
            last edited by Claudia Frank

            @Pouemes44

            I’m not really good in regex explanations but I’ll give it a try.

            each of the () denote a matching group which can be reflected by using a dollar sign and a number.
            $1 for the first matching group, $2 for the second and so on.

            So what get’s matched in (<a.?>) is stored in $1,
            (*\x20) in $2 and (.
            ?</a>) in $3

            (<a.*?>) = we are looking for something which starts with <a
            followed by .* means anything either none or multiple time,
            the question mark restricts that it should be as less as possible
            chars consumed followed by >.

            (*\x20) we are looking for the asteriks and \x20 is the hexcode for a space

            and last but not least, (.*?</a>) which is basically similar to the first.

            In the replace with field you ignore the second matching group as you want to get rid of the asteriks and space,
            instead you type it in front of the $1$3 because that is what you wanted.

            Better described at http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html.

            Cheers
            Claudia

            1 Reply Last reply Reply Quote 0
            • guy038G
              guy038
              last edited by

              Hello, @pouemes44, @claudia-franck and All,

              An other solution could be :

              SEARCH (?-s)\*\x20+(?=.+?</a>)

              REPLACE Leave EMPTY

              Notes :

              • As usual, the modifier (?-s) means that the dot, ., matches a single standard character, only

              • Then, the regex engine is looking for a literal star symbol ( \* ) followed by at least one space character ( \x20+ )

              • But, ONLY, if the look-ahead is verified. That is to say, IF it exists, further on, an ending tag </a>, on the same line

              • As the replacement zone is empty , the combination star + space(s) is simply deleted !


              Of course, if the syntax \*\x20+ occurs, ONLY, in blocks <a ......>......</a> of your file, just use :

              SEARCH \*\x20+

              REPLACE Leave EMPTY

              Best Regards,

              guy038

              1 Reply Last reply Reply Quote 0
              • Pouemes44P
                Pouemes44
                last edited by

                thanks both for explanations

                but guy with your solution, its only delete all *space but not move them before <a

                1 Reply Last reply Reply Quote 0
                • Pouemes44P
                  Pouemes44
                  last edited by

                  and claudia i just saw that your solution does errors

                  <a href=“/url/page.html”>name</a>
                  <a href=“/url/other.html”>name2</a>
                  <a href=“/url/third.html”>etc</a>
                  <a href=“/url/four.html”>* something</a>

                  give

                  • <a href=“/url/page.html”>name</a>
                    <a href=“/url/other.html”>name2</a>
                    <a href=“/url/third.html”>etc</a>
                    <a href=“/url/four.html”>something</a>

                  i would

                  <a href=“/url/page.html”>name</a>
                  <a href=“/url/other.html”>name2</a>
                  <a href=“/url/third.html”>etc</a>

                  • <a href=“/url/four.html”>something</a>
                  1 Reply Last reply Reply Quote 0
                  • Pouemes44P
                    Pouemes44
                    last edited by

                    like this seems to works

                    search (?-s)(<a.+?">)+*\x20+(?=.+?</a>)
                    replace * $1

                    1 Reply Last reply Reply Quote 0
                    • Pouemes44P
                      Pouemes44
                      last edited by

                      @guy038 said:

                      this two
                      (?-s)(<a.+?">)*\x20
                      replace * $1

                      Claudia FrankC 1 Reply Last reply Reply Quote 1
                      • Claudia FrankC
                        Claudia Frank @Pouemes44
                        last edited by Claudia Frank

                        @Pouemes44

                        I don’t see really the difference, I guess because the markdown used some of your chars for formatting.
                        To prevent this you can either indent every line with 4 spaces or escape the markdown characters with
                        a backslash, like

                        * whatever */
                        

                        I had just to put 4 spaces in front of the asteriks and every single character is shown whereas here

                        *whatever*/

                        I had to write \*whatever*/ to inform markdown that the asteriks should be displayed and not used to reformat text.

                        Anyway, good to see that you have found your solution.

                        Cheers
                        Claudia

                        1 Reply Last reply Reply Quote 0
                        • Pouemes44P
                          Pouemes44
                          last edited by

                          yes claudia,
                          i dont know what was the poblem with your solution
                          anyway i succeed
                          a great thanks

                          1 Reply Last reply Reply Quote 0
                          • guy038G
                            guy038
                            last edited by guy038

                            Hi, @pouemes44, @claudia-frank and All,

                            I apologize, Pouemess44, because I didn’t read your post carefully :-( I should have read the line :

                            so to put the * before <a

                            and, also, the title of your post !

                            move * before

                            So, seemingly, from the initial text :

                              <a href=“url/myurl.htm”>* name</a>
                            

                            Your goal is to obtain the text below :

                              *<a href=“url/myurl.htm”>name</a>
                            

                            In that case, you’re perfectly right ! A correct regex S/R is, very similar to yours, is :

                            SEARCH (?-s)(<a href.+?>)\*\x20+

                            REPLACE *$1

                            Cheers,

                            guy038

                            P.S. :

                            I guess that Claudia did the same mistake than me !! So, the correct Claudia’s regex S/R is, rather :

                            SEARCH (<a.*?>)(\*\x20)(.*?<\/a>)

                            REPLACE *$1$3

                            1 Reply Last reply Reply Quote 0
                            • Pouemes44P
                              Pouemes44
                              last edited by

                              @guy038 said:

                              (?-s)

                              hello thanks for answer
                              i try also to learn
                              for claudia solution i have no error if i add (?-s)

                              like this
                              (?-s)(<a.?>)(*\x20)(.?</a>)

                              • $1$3

                              without (?-s) or with (?s) i get errors in results

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