inserting ' and ', in long group of attributes



  • Hi,
    may times i must insert ’ and ', in a long group of attributes, namelly a column from a sql query that i must search using operator “in” in another query…
    is there any way to do this in notepad++??

    Example:
    codea
    codeb b
    codec c c

    (1 thousand codes after)
    code1 2 10 20

    Adapt this to:
    ‘codea’,
    ‘codeb b’,
    ‘codec c c’,

    (1 thousand codes after)
    ‘code1 2 10 20’

    so that finally i can do this in sql server:
    select * from table1 where code in
    (
    ’codea’,
    ‘codeb b’,
    ‘codec c c’,

    (1 thousand codes after)
    'code1 2 10 20’

    (

    Thank you and regards



  • Hello @Ricardo-Magalhães-Mota-Freitas,

    if this a column and you want to add a single quote in front and a single quote and a comma at the end of each line,
    then we could search and replace with regular expression like

    find what: ^(.+)$
    replace with: '\1',
    

    ^= start of the line
    $ = end of the line
    (.+) = match at least one char

    \1 = what got matched

    Cheers
    Claudia



  • @Claudia-Frank said:

    Hello @Ricardo-Magalhães-Mota-Freitas,

    if this a column and you want to add a single quote in front and a single quote and a comma at the end of each line,
    then we could search and replace with regular expression like

    find what: ^(.+)$
    replace with: ‘\1’,
    ^= start of the line
    $ = end of the line
    (.+) = match at least one char

    \1 = what got matched

    Cheers
    Claudia

    Jeeesus!
    Claudia thank you so much for your help :)
    i think i will live more 1 month in my life with this tip…



  • Glad to see that I helped to extend your life ;-D

    Cheers
    Claudia



  • Hi, Ricardo and Claudia,

    The Claudia’s regex is quite correct. however, we can, even, shorten it !

    Find what    :  .+
    
    Replace with :  '$0',
    

    NOTES :

    In the replacement field, the syntax $n has two interesting properties :

    • The syntax $0 represents the entire searched match. So, in our example, the regex .+, that is to say, each non empty line. And the $0 syntax prevents us from surrounding the searched group with the normal two round brackets !

    • Contrary to the syntax \n ( with 1<=n<=9 ), which represents the contents of the searched groups 1 to 9, the syntax $n is valid, for any group, even higher than 9 !

    In the particular case, when the contents of the group n, must be followed, in replacement, with a digit, we just use the ${n} syntax, to separate the group designation, from the next digit. For instance, the following S/R, below :

    Find what    :  .+
    
    Replace with :  00${0}00
    

    would replace any non empty line of a file by the same line, surrounded by the string 00

    Cheers,

    guy038



  • Hey, guy038,

    tricky, but where does this $0 come from?

    Cheers
    Claudia



  • Hi, Claudia,

    Just look the section Placeholder Sequences, from the Boost-Extended Format String Syntax article :

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

    Regards,

    guy038


Log in to reply