Find / Replace two letter words with " " around them



  • 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?



  • 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



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



  • @Francis-Neal

    Something like this might meet your need:

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



  • 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



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


Log in to reply