Community
    • Login

    Find / Replace two letter words with " " around them

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 1.6k 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.
    • Francis NealF
      Francis Neal
      last edited by

      Hi I have a list of words, either 1 or 2 words long. I want to find all 2 letter words, eg south korea, and replace it with “south korea”. How do I do this?

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

        Hello, @Francis Neal, and All,

        I’m pretty sure that we lack some information !

        Let’s suppose the sentence : This is a simple sample sentence

        Do you mean that you expect the result "This is" "a simple" "sample sentence" or do I misunderstand you ?

        See you later,

        Best regards,

        guy038

        1 Reply Last reply Reply Quote 0
        • Francis NealF
          Francis Neal
          last edited by

          marine
          aviation
          harley davidson
          social work
          south korea
          trentham
          quantity surveyor
          mortgage advisor
          ride on cars
          cable jointing
          theatre technician
          heavy plant
          career racing
          electro mechanical
          air condiioning
          british airways
          aircraft
          stansted
          air conditioning
          civil engineering
          agriculture

          Above is a sample of the list. I want to find all 2 word lines, and put “” around them. so civil engineering becomes “civil engineering” . Apologies for the lack of info previously. :-)

          Alan KilbornA 1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @Francis Neal
            last edited by

            @Francis-Neal

            Something like this might meet your need:

            Find what: ^\w+\W\w+$
            Replace with: "$0"
            Mode: Reg Exp

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

              Hi, @Francis-Neal, and All,

              Ah I see ! Thanks for your reply.

              Oh, I just realized that Alan beat me to it ;-)

              So, open the Replace dialog

              • Type in the regex \w+(\h+\w+)+ in the Find what: zone

              • Type in the regex "$0" in the Replace with: zone

              • Check the Wrap around option

              • Select the Regular expression search mode

              • Click, once on the Replace All button or several times on the Replace button

              Et voilà !

              Notes :

              • The part \w+ looks for a non-empty range of word characters ( roughly [A-Za-z0-9_] )

              • The part \h+\w+ represents any non-empty list of horizontal blank characters ( so, either a Space, Tabulation or No-Break char ), followed with a non-empty range of words characters, again

              • As this part is embedded in a (....)+ syntax, the blank + word set may be repeated, any time

              • In replacement, $0 is the overall match, which is surrounded with two " characters

              Cheers,

              guy038

              P.S. :

              I supposed that any line, containing more than one word, must be surrounded with double quotes !


              An other search syntax could be :

              SEARCH (?-s)(?=.+\h).+

              Notes :

              • The part (?-s) is an in-line modifier which tells the regex engine that the dot ( . ) will match a single standard character, only

              • Then the part (?=.+\h) is a positive look-ahead structure, which needs to be true for an overall match i.e. So the condition : is there, from current position, an horizontal blank char, further on, in current line ?

              • Finally, if answer is true, the regex engine tries to match the .+ regex, i.e. all the line contents

              1 Reply Last reply Reply Quote 2
              • Francis NealF
                Francis Neal
                last edited by

                Thanks both, just what I wanted absolutely brilliant. Thanks also for the detailed explanation guy038 :-)

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