Navigation

    Community

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

    Some simple regex questions.

    Help wanted · · · – – – · · ·
    4
    8
    1410
    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.
    • LAPIII
      LAPIII last edited by

      1. How can I add a comma only to the ends of lines with text?
      2. How do I combine lines?
      3. Replace letters of a word, e.g. ‘er’ with ‘s’?
      Scott Sumner 1 Reply Last reply Reply Quote 0
      • Scott Sumner
        Scott Sumner @LAPIII last edited by Scott Sumner

        @LAPIII

        1. FW: (?-s).+ RW: $0,
        2. FW: \R RW: make sure it is empty
        3. You mean like at the end of a word?? Maybe… FW: er\b RW: s

        But really, don’t use this forum as a basic regex learning place (much better places for that)

        1 Reply Last reply Reply Quote 3
        • Meta Chuh
          Meta Chuh last edited by

          @LAPIII

          if you have a text like:

          line 1
          line 2
          line 3
          line 4
          line 5
          

          How can I add a comma only to the ends of lines with text?:
          find what: ^(.*?)$
          replace with: $1,
          search mode: regular expression

          result:

          line 1,
          line 2,
          line 3,
          line 4,
          line 5,
          

          How do I combine lines?:
          find what: \r?\n|\r
          replace with: (one single space)
          search mode: regular expression

          result:

          line 1, line 2, line 3, line 4, line 5,
          

          Replace letters of a word, e.g. ‘in’ with ‘s’?:
          find what: in
          replace with: s
          search mode: regular expression or normal

          result:

          lse 1, lse 2, lse 3, lse 4, lse 5,
          
          Claudia Frank 1 Reply Last reply Reply Quote 2
          • Claudia Frank
            Claudia Frank @Meta Chuh last edited by Claudia Frank

            @Scott-Sumner @Meta-Chuh

            concerning the question 1
            How can I add a comma only to the ends of lines with text?

            a regex like (?-s)\w+.*$ might suit better, doesn’t it?
            and replace with $0,

            Cheers
            Claudia

            Scott Sumner 1 Reply Last reply Reply Quote 2
            • Scott Sumner
              Scott Sumner @Claudia Frank last edited by

              @Claudia-Frank

              OH MY ! … I’m not getting into what with text means if the OP can’t be specific. Notepad++ is a text editor…it’s ALL TEXT!!

              [Okay, I’ll get into it…because someone will call me out on it and say that a line-ending is also text…sigh…I took lines with text to mean non-empty lines.]

              :-D

              Claudia Frank 1 Reply Last reply Reply Quote 1
              • Claudia Frank
                Claudia Frank @Scott Sumner last edited by

                @Scott-Sumner

                as you probably already found out, today I’m in guess mode :-D,
                so, who knows, at the end it might be that OP was exactly asking
                what you and @Meta-Chuh proposed a solution for.

                Cheers
                Claudia

                1 Reply Last reply Reply Quote 2
                • Scott Sumner
                  Scott Sumner last edited by

                  Curious as to how @Meta-Chuh interpreted the OP’s need, because the suggestion of ^(.*?)$ matches empty lines as well as non-empty…

                  Meta Chuh 1 Reply Last reply Reply Quote 2
                  • Meta Chuh
                    Meta Chuh @Scott Sumner last edited by

                    @Scott-Sumner

                    you are right (empty lines).
                    today we just both hit submit at about the same time, otherwise i’d seen your answer and not have given an extra solution if an existing post does the requested job and no further request is given by the OP.

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