• Login
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.
  • F
    Francis Neal
    last edited by Jan 18, 2019, 12:01 PM

    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
    • G
      guy038
      last edited by guy038 Jan 18, 2019, 12:26 PM Jan 18, 2019, 12:21 PM

      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
      • F
        Francis Neal
        last edited by Jan 18, 2019, 12:30 PM

        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. :-)

        A 1 Reply Last reply Jan 18, 2019, 12:50 PM Reply Quote 1
        • A
          Alan Kilborn @Francis Neal
          last edited by Jan 18, 2019, 12:50 PM

          @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
          • G
            guy038
            last edited by guy038 Nov 2, 2022, 1:27 PM Jan 18, 2019, 12:56 PM

            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
            • F
              Francis Neal
              last edited by Jan 18, 2019, 1:52 PM

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

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