• Login
Community
  • Login

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

Scheduled Pinned Locked Moved General Discussion
11 Posts 4 Posters 489 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.
  • R
    Regina Oswald
    last edited by Jun 21, 2021, 3:01 PM

    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?

    A 1 Reply Last reply Jun 21, 2021, 3:21 PM Reply Quote 1
    • A
      astrosofista @Regina Oswald
      last edited by Jun 21, 2021, 3:21 PM

      @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

      R 1 Reply Last reply Jun 21, 2021, 4:03 PM Reply Quote 2
      • R
        Regina Oswald @astrosofista
        last edited by Regina Oswald Jun 21, 2021, 4:04 PM Jun 21, 2021, 4:03 PM

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

        A A 2 Replies Last reply Jun 21, 2021, 5:05 PM Reply Quote 1
        • A
          Alan Kilborn @Regina Oswald
          last edited by Jun 21, 2021, 5:05 PM

          @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

          R 1 Reply Last reply Jun 21, 2021, 5:13 PM Reply Quote 2
          • A
            astrosofista @Regina Oswald
            last edited by Jun 21, 2021, 5:08 PM

            @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
            • R
              Regina Oswald @Alan Kilborn
              last edited by Jun 21, 2021, 5:13 PM

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

              A 1 Reply Last reply Jun 21, 2021, 5:15 PM Reply Quote 1
              • A
                Alan Kilborn @Regina Oswald
                last edited by Alan Kilborn Jun 21, 2021, 5:17 PM Jun 21, 2021, 5:15 PM

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

                R 1 Reply Last reply Jun 23, 2021, 4:26 AM Reply Quote 3
                • G
                  guy038
                  last edited by Jun 22, 2021, 2:00 AM

                  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

                  R 1 Reply Last reply Jun 23, 2021, 4:24 AM Reply Quote 1
                  • R
                    Regina Oswald @guy038
                    last edited by Jun 23, 2021, 4:24 AM

                    @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
                    • R
                      Regina Oswald @Alan Kilborn
                      last edited by Jun 23, 2021, 4:26 AM

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

                      A 1 Reply Last reply Jun 23, 2021, 11:46 AM Reply Quote 0
                      • A
                        Alan Kilborn @Regina Oswald
                        last edited by Jun 23, 2021, 11:46 AM

                        @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
                        2 out of 11
                        • First post
                          2/11
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors