Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    inserting ' and ', in long group of attributes

    General Discussion
    3
    7
    8144
    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.
    • Ricardo Magalhães Mota Freitas
      Ricardo Magalhães Mota Freitas last edited by

      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

      Claudia Frank 1 Reply Last reply Reply Quote 0
      • Claudia Frank
        Claudia Frank @Ricardo Magalhães Mota Freitas last edited by

        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

        1 Reply Last reply Reply Quote 0
        • Ricardo Magalhães Mota Freitas
          Ricardo Magalhães Mota Freitas last edited by

          @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…

          1 Reply Last reply Reply Quote 0
          • Claudia Frank
            Claudia Frank last edited by

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

            Cheers
            Claudia

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

              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

              Claudia Frank 1 Reply Last reply Reply Quote 0
              • Claudia Frank
                Claudia Frank @guy038 last edited by

                Hey, guy038,

                tricky, but where does this $0 come from?

                Cheers
                Claudia

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

                  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

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Copyright © 2014 NodeBB Forums | Contributors