Community
    • Login

    How to add a blank space and a word before every comma in some meta tags in every html file of a folder?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    22 Posts 5 Posters 1.0k 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.
    • Ramanand JhingadeR
      Ramanand Jhingade @Ramanand Jhingade
      last edited by

      @PeterJones I am trying - please see what I posted just above. Thanks for the advice!

      Ramanand JhingadeR 1 Reply Last reply Reply Quote 0
      • Ramanand JhingadeR
        Ramanand Jhingade @Ramanand Jhingade
        last edited by Ramanand Jhingade

        @guy038 Will (?-s)(?-i:<META\x20|(?!\A)\G).*?\K(?-i:Cure|cure) help find all instances of Cure and cure till the beginning of the next meta tag?

        1 Reply Last reply Reply Quote 0
        • Ramanand JhingadeR
          Ramanand Jhingade
          last edited by Ramanand Jhingade

          @guy038 I have understood this much: $0 Inserts all text matched in the regex (automatic unnamed capture) and \x20 adds a space, g searches for a string repeatedly. The rest is still “Latin” and “Greek” to me. I, therefore, request you to help find the word cure wherever it appears in the META tag (not just in the first line) so that I can replace it.

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @Ramanand Jhingade
            last edited by

            @Ramanand-Jhingade said in How to add a blank space and a word before every comma in some meta tags in every html file of a folder?:

            The rest is still “Latin” and “Greek” to me. I, therefore, request you to help

            Thank you for trying to understand. But like learning Latin and Greek, you cannot expect to be an expert in regex in one afternoon. But just because you’re not a Latin/Greek expert doesn’t give you permission to go into a forum on ancient texts and ask them to translate a manuscript you just found, for free, on your terms and on your timeline. When they point you to courses or websites on learning ancient Latin and Greek, you are expected to then go avail yourself of that documentation and give it a shot yourself.

            Guy gave you the formula for “change X into Y, but only when it’s between START and END” (using “FR”, “RR”, “BSR”, “ESR”). And he even gave you the first version of what those markers should be, based on your data. Try applying what you learned. If you get stuck, show us what you tried and why you thought it would work, an example of the data input, and how the output differs from what you expected.

            Instead, you give a one sentence of “I tried something, and it didn’t work, so just do it for me”, which is an attitude not appreciated here.

            Guy will likely come back and hand you yet another answer, and that’s his prerogative. But until you start trying to learn this, it’s going to remain foreign to you, and you’re going to continue to struggle.

            Also understand: a lot of what people think are going to be “easy” search-and-replace requests are actually very involved. The “change X into Y, but only when it’s between START and END” sounds easy, but the answer is complicated; that’s why Guy went to the trouble of figuring out the generic formula for that request, which is about as plug-and-play as a regex gets. But sometimes, you are going to have to try various things on your own until you figure it out.

            This forum is not a do-my-data-manipulation-for-me-for-free location. We point people to initial answers about regex to inform them that Notepad++'s regex can do a lot, and that if they invest the time in learning regex, they will be able to eventually figure out how to do their own data manipulation for themselves.

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

              Hi, @ramanand-jhingade, @peterjones and All,

              To @peterjones :

              I fully support what you said to @ramanand-jhingade. However, I considered that my previous post could be worth to, as it gave, from the same generic regex S/R adapted to mono-lines search, described below, two different solutions for two different goals !

              SEARCH (?-s)(?-i:BSR|(?!\A)\G).*?\K(?-i:FR)

              REPLACE RR

              where :

              • BSR is the Begin Search-region Regex expression to search BEFORE any FR string located in current line

              • FR is the Find Regex expression, which may be present once or several times in current line

              • RR is the Replace Regex expression, which replaces any FR expression found in current line


              To @ramanand-jhingade :

              • The (?-i:This is a Text) syntax is a non-capturing group which searches for the exact string This is a Text

              • The (?i:This is a Text) syntax is a non-capturing group which searches for the string This is a Text whatever its case. For instance, this regex may find any of these expressions :

                • This is a Text

                • this is a text

                • This Is A Text

                • tHIs iS a teXT

                • THIS IS A TEXT

              • Similarly, the (?-i)(This is a Text) syntax is a capturing group which searches for the exact string This is a Text

              • The (?i)(This is a Text) syntax is a capturing group which searches for the string This is a Text whatever its case. For instance, this regex may find any of these expressions :

                • this is A TEXT

                • THIS IS a text

                • ThIs Is A TeXt


              You also said :

              g searches for a string repeatedly

              Not exactly ! We’re are speaking about the \G assertion ( i.e. a condition ) which is TRUE only if the present match IMMEDIATELY follows the previous match !. For instance, let’s imagine the regex \Ga against the text, below, in a new tab

              aaaaaabaaaaaaa
              aaaaaabaaaaaaa
              
              • Move the cursor at the very beginning ( Ctrl + Home)

              • Search \Ga

              • Hit repeatedly on the Find Next button

              => As you can see, it will match any a letter and stop when meeting the b letter. Logical, as the next a char, so the future match, does not immediately follows the previous a letter

              • Now, move the caret right after the b letter. Again, any a letter is matched but note that it stops after the last char of the first line. Again, this behaviour is logical as, between the last a and the next a, there are the two Windows line-break chars ( CR and LF ). So, the two matches are not consecutive !

              • And, if you move the caret at beginning of the second line, again, the regex engine will match any a letter till the b letter !

              I must admit that the \G assertion, even when explained, is not easy to handle ! At least, much less than the usual ^ and $ assertions which match the zero-length locations Beginning and End of current line !

              But modifiers, non-capturing and capturing groups are well explained in most of regex tutorials ! So, no matter, you need to "read this fucking manual" !!

              You will probably be disappointed by your first attempts but you will progress ! No doubt about it !

              Best Regards,

              guy038

              Ramanand JhingadeR 1 Reply Last reply Reply Quote 1
              • Ramanand JhingadeR
                Ramanand Jhingade @guy038
                last edited by

                @guy038 You are talking of what is available here: Notepad User Manual right?

                PeterJonesP 1 Reply Last reply Reply Quote 0
                • PeterJonesP
                  PeterJones @Ramanand Jhingade
                  last edited by

                  @Ramanand-Jhingade said in How to add a blank space and a word before every comma in some meta tags in every html file of a folder?:

                  You are talking of what is available here: Notepad User Manual right?

                  Yes. Specifically, as I posted earlier:

                  Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ.

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

                    Hi, @ramanand-jhingade

                    Yes and more precisely :

                    • https://npp-user-manual.org/docs/searching/ about the general concept of searching

                    • https://npp-user-manual.org/docs/searching/#regular-expressions about regular expressions

                    A valuable site (and the reference !) is that one, too ( not especially devoted to the Boost regex library, used within N++ ) :

                    • https://www.regular-expressions.info/

                    And begin with https://www.regular-expressions.info/quickstart.html


                    Of course, you need two weeks, minimum, to feel at ease with simple goals and, let’s say, three months to become fluent to regex syntaxes in order to modify 90 % texts as you want to, about. For the remaining 10 % you’re welcome and we’ll probably find out a suitable solution !

                    Note that, with the knowledge of basic regexes syntax, the provided solutions should enlighten you much better than at present, without the necessary background !

                    BR

                    guy038

                    Ramanand JhingadeR 2 Replies Last reply Reply Quote 1
                    • Ramanand JhingadeR
                      Ramanand Jhingade @guy038
                      last edited by

                      @guy038 I was able to do what I wanted by using this Regex in the “Find All” field: (?-s)(?-i:<META\x20|(?!\A)\G).*?\Kcure and this cure\x20for in the “Replace in Files” field. Thanks for the idea. Now, a lot of people will find this page through search engines, so just for their convenience and information please do let us know how to search for more than one string of characters and add a word with a space to the end of that string but where the search is limited to the Meta tags (it should not search the rest of the file)

                      1 Reply Last reply Reply Quote 0
                      • Ramanand JhingadeR
                        Ramanand Jhingade @guy038
                        last edited by

                        @guy038 This:-
                        SEARCH (?-s)(?-i:<META\x20|(?!\A)\G).*?\K(?-i:Homeopathic (treatment|doctor|clinic|specialist)|Homeopathy)

                        REPLACE ALL $0\x20for
                        did not work for me!

                        1 Reply Last reply Reply Quote 0
                        • Reza SaputraR
                          Reza Saputra
                          last edited by

                          4f651887-cef6-4008-afc9-ccea9503de5d-image.png

                          How about this bro?

                          Ramanand JhingadeR 1 Reply Last reply Reply Quote 0
                          • Ramanand JhingadeR
                            Ramanand Jhingade @Reza Saputra
                            last edited by Ramanand Jhingade

                            @Reza-Saputra I already searched for each word individually and replaced each with the code I posted for searching for the word, “cure” which was originally given by @guy038 that is (?-s)(?-i:<META\x20|(?!\A)\G).*?\Kcure and this cure\x20for
                            However, I can tell you that h finds one horizontal whitespace character: tab or Unicode space separator that is it!

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

                              Hello, @ramanand-jhingade,

                              You said :

                              please do let us know how to search for more than one string of characters and add a word with a space to the end of that string but where the search is limited to the Meta tags (it should not search the rest of the file)

                              Well, from the two parts of this previous post and from what I specifically wrote to @peterjones, here, you should had guessed how to do it !

                              Indeed, from the generic regex :

                              SEARCH (?-s)(?-i:BSR|(?!\A)\G).*?\K(?-i:FR)

                              REPLACE RR

                              where :

                              • BSR is the Begin Search-region Regex expression to search BEFORE any FR string located in current line

                              • FR is the Find Regex expression, which may be present once or several times in current line

                              • RR is the Replace Regex expression, which replaces any FR expression found in current line

                              we can build up the suitable regex in order to look for, let’s say, 4 different words Word_1, Word_2, Word_3 and Word_4, in meta tags only, written in a single line and add, after each of them, the word WORD !

                              • BSR ( Begin Search-region Regex ) = <META\x20

                              • FR ( Find Regex ) = Word_1|Word_2|word_3|Word_4

                              • RR ( Replace Regex ) = $0\x20WORD

                              leading to the right regex S/R :

                              SEARCH (?-s)(?-i:<META\x20|(?!\A)\G).*?\K(?-i:Word_1|Word_2|word_3|Word_4)

                              REPLACE $0\x20WORD


                              Now, you said :

                              SEARCH (?-s)(?-i:<META\x20|(?!\A)\G).*?\K(?-i:Homeopathic (treatment|doctor|clinic|specialist)|Homeopathy)

                              REPLACE $0\x20for

                              did not work for me!

                              Well, may be try this one :

                              SEARCH (?-s)(?-i:<META\x20|(?!\A)\G).*?\K(?-i:Homeopathic\h+(treatment|doctor|clinic|specialist)|Homeopathy)

                              REPLACE $0\x20for

                              If it does not work either, just send me your file by e-mail. Refer to this post, to get my temporary e-mail address !

                              BR

                              guy038

                              Ramanand JhingadeR 1 Reply Last reply Reply Quote 1
                              • Ramanand JhingadeR
                                Ramanand Jhingade @guy038
                                last edited by Ramanand Jhingade

                                @guy038 I already searched for each word individually and replaced each with the code you posted here first to search for the META tag and comma. I used it to search for the word, “Homeopathy”, with this RegEx: (?-s)(?-i:<META\x20|(?!\A)\G).*?\KHomeopathy and replaced it with this: Homeopathy\x20for so I will not bother you again.
                                I am glad you replied - I think you realised that doing this is was beyond my present abilities and comprehension!

                                1 Reply Last reply Reply Quote 1
                                • A
                                  Acme1235
                                  last edited by

                                  Just an FYI a good place to learn regex and test your code is regex101.com

                                  PeterJonesP 1 Reply Last reply Reply Quote 0
                                  • PeterJonesP
                                    PeterJones @Acme1235
                                    last edited by

                                    @Acme1235 said in How to add a blank space and a word before every comma in some meta tags in every html file of a folder?:

                                    Just an FYI a good place to learn regex and test your code is regex101.com

                                    … which is linked to in the Regular Expression FAQ that we have repeatedly asked Ramanand to read.

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