Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Problem with find / replace with wildcards. Will put in the same Regular expression twice

    General Discussion
    4
    11
    91
    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.
    • Regina Oswald
      Regina Oswald last edited by

      I have a document like this:

      $node->field_it_themenueberschrift_dt
      $node->field_it_themenueberschrift_2
      $node->field_it_themenueberschrift_3
      $node->field_it_themenueberschrift_4
      $node->field_it_thementext_dt
      $node->field_it_thementext_2
      $node->field_it_thementext_3
      $node->field_it_thementext_4
      $node->field_it_qr_code_dt
      $node->field_it_qr_code_2
      $node->field_it_qr_code_3
      $node->field_it_qr_code_4
      

      I would like to put a div container with class appanding to the name of variable arround it like this:
      For example it should look like this:
      <div class='qr_code_4'>$node->field_it_qr_code_4</div>

      I tried this way:
      search: \$node->field_it_(.*?)
      replace with: <div class='(\1)'>$node->field_it_(\1)</div>
      I get:

      <div class=''>$node->field_it_</div>themenueberschrift_dt
      <div class=''>$node->field_it_</div>themenueberschrift_2
      <div class=''>$node->field_it_</div>themenueberschrift_3
      <div class=''>$node->field_it_</div>themenueberschrift_4
      <div class=''>$node->field_it_</div>thementext_dt
      <div class=''>$node->field_it_</div>thementext_2
      <div class=''>$node->field_it_</div>thementext_3
      <div class=''>$node->field_it_</div>thementext_4
      

      What did I wrong?

      astrosofista 1 Reply Last reply Reply Quote 1
      • astrosofista
        astrosofista @Regina Oswald last edited by

        @Regina-Oswald

        You matched an empty string with the ungreedy expression (.*?). Try this instead:

        Search: (?-s)(\$node->field_it_(.*))$
        Replace: <div class='($2)'>$1</div>
        

        Hope this helps

        Regina Oswald 1 Reply Last reply Reply Quote 2
        • Regina Oswald
          Regina Oswald @astrosofista last edited by Regina Oswald

          @astrosofista said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:

          <div class=‘($2)’>$1</div>

          Hey You are my hero. ;-)
          This is the solution.

          But whre can i find the documentation for this?
          I know the expression $2 from htaccess and other script languages.
          But for Notepad i found the solution with (\1).
          And the (?-s) expression i did not find.
          It is to avoid hungry behavior?
          Like -U with PHP preg_replace?

          Until now I worked with Textpad-Editor.
          There i would do it with &
          But notepad has better Syntax Highlighting. Therefor i would like to learn more.

          Thank You very much.

          Alan Kilborn astrosofista 2 Replies Last reply Reply Quote 1
          • Alan Kilborn
            Alan Kilborn @Regina Oswald last edited by

            @Regina-Oswald said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:

            But whre can i find the documentation for this?

            The Notepad++ user manual is one place.
            See https://npp-user-manual.org/
            And specifically for searching, see https://npp-user-manual.org/docs/searching/
            And very specifically for regular expressions see https://npp-user-manual.org/docs/searching/#regular-expressions

            Regina Oswald 1 Reply Last reply Reply Quote 2
            • astrosofista
              astrosofista @Regina Oswald last edited by

              @Regina-Oswald

              Glad I could helped you. You were really close to a working solution. Also the issue were clearly explained. Thank you for that, makes easier for us to help people.

              Concerning the documentation, you can read the regex guide in the FAQ section of this forum, which also includes links to more advanced docs.

              $n and \n means the same, they are references to groups, just I am used to the first one.

              And the (?-s) expression overrules the . matches newline option, so one is sure that the all text will not be considered as a single line, which will be correct on the example data you provided.

              1 Reply Last reply Reply Quote 2
              • Regina Oswald
                Regina Oswald @Alan Kilborn last edited by

                @Alan-Kilborn said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:

                The Notepad++ user manual is one place.

                Thanks also to You.
                I seeked half day for the links to doc and found only very old docs ore broken links.
                Obviously I did not have the right search terms.

                Alan Kilborn 1 Reply Last reply Reply Quote 1
                • Alan Kilborn
                  Alan Kilborn @Regina Oswald last edited by Alan Kilborn

                  @Regina-Oswald said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:

                  I seeked half day for the links to doc and found only very old docs ore broken links.

                  Well, if you go to Notepad++ 's home site:
                  https://notepad-plus-plus.org/

                  There appears a link there called “Online Help” and if you click that there will be a link to the user manual that I shared the link of earlier.

                  Not all that difficult to find.

                  OR…

                  In Notepad++ 's ? menu, there is an entry for Online Documentation that will take you there as well:

                  dae7de60-ca93-414f-b649-eea91dc8335e-image.png

                  This stuff is about as easy/difficult to find as the site we’re now on, so…

                  Regina Oswald 1 Reply Last reply Reply Quote 3
                  • guy038
                    guy038 last edited by

                    Hello, @regina-oswald, @astrosofista, @alan-kilborn and All,

                    @regina-oswald, here is my version of your goal :

                    SEARCH (?-s)^\$node->field_it_(.+)

                    REPLACEMENT <div class='\1'>$0</div>


                    Notes :

                    • In search, the (?-s) in-line modifier forces a . to be an unique standard character ( not a line-break char ) and the + syntax represents the {1,} quantifier, meaning all the remaining chars of current line, after the >field_it_ string

                    • In replacement, the $0 syntax stands for the overall match so, in your case, for each complete line, without its line-break char(s)

                    Best Regards,

                    guy038

                    Regina Oswald 1 Reply Last reply Reply Quote 1
                    • Regina Oswald
                      Regina Oswald @guy038 last edited by

                      @guy038 said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:

                      SEARCH (?-s)^$node->field_it_(.+)
                      REPLACEMENT <div class=‘\1’>$0</div>

                      Thanks also to You.
                      Interesting.

                      1 Reply Last reply Reply Quote 0
                      • Regina Oswald
                        Regina Oswald @Alan Kilborn last edited by

                        @Alan-Kilborn said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:

                        This stuff is about as easy/difficult to find as the site we’re now on, so…

                        I found the online-Documentation but not the special goal with twice repleacing of the same regular expression.

                        Alan Kilborn 1 Reply Last reply Reply Quote 0
                        • Alan Kilborn
                          Alan Kilborn @Regina Oswald last edited by

                          @Regina-Oswald said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:

                          but not the special goal with twice repleacing of the same regular expression

                          I’m actually not sure what you are meaning by that.
                          I suspect it might mean something very specific to the replacement you wanted to do.
                          The documentation is only going to describe the capabilities; it can’t possibly describe all possible application nuances of those capabilities.

                          1 Reply Last reply Reply Quote 1
                          • First post
                            Last post
                          Copyright © 2014 NodeBB Forums | Contributors