• Login
Community
  • Login

Some simple regex questions.

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 4 Posters 1.8k 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.
  • L
    LAPIII
    last edited by May 3, 2018, 2:36 PM

    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’?
    S 1 Reply Last reply May 3, 2018, 3:12 PM Reply Quote 0
    • S
      Scott Sumner @LAPIII
      last edited by Scott Sumner May 3, 2018, 3:14 PM May 3, 2018, 3:12 PM

      @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
      • M
        Meta Chuh moderator
        last edited by May 3, 2018, 3:23 PM

        @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,
        
        C 1 Reply Last reply May 3, 2018, 3:40 PM Reply Quote 2
        • C
          Claudia Frank @Meta Chuh
          last edited by Claudia Frank May 3, 2018, 3:41 PM May 3, 2018, 3:40 PM

          @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

          S 1 Reply Last reply May 3, 2018, 3:57 PM Reply Quote 2
          • S
            Scott Sumner @Claudia Frank
            last edited by May 3, 2018, 3:57 PM

            @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

            C 1 Reply Last reply May 3, 2018, 4:05 PM Reply Quote 1
            • C
              Claudia Frank @Scott Sumner
              last edited by May 3, 2018, 4:05 PM

              @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
              • S
                Scott Sumner
                last edited by May 3, 2018, 5:26 PM

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

                M 1 Reply Last reply May 3, 2018, 6:48 PM Reply Quote 2
                • M
                  Meta Chuh moderator @Scott Sumner
                  last edited by May 3, 2018, 6:48 PM

                  @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
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors