Menu

Line Start in Regular Expression

2006-12-08
2012-11-13
  • Nobody/Anonymous

    I am trying to use regular expression in Search and Replace to put a hyphen at the beginning of each line.

    Search: ^
    Replace -

    This does not work.  The error is "The regular expression to search is formed badly".

    How do I do this in Notepad Plus?  This regular expression works in other programs.

    Thanks
    Paul

     
    • pshute

      pshute - 2006-12-11

      That sounds like a bug.  There are several ways to do this kind of thing.  Have a read of http://notepad-plus.sourceforge.net/uk/newlineFindReplace-HOWTO.php and hopefully you'll find a method that works.

       
    • Olivier Croquette

      Hi,

      it seems the bug is still there. I have the same problem. Shall we open a new bug report?

       
      • pshute

        pshute - 2007-07-12

        It's a well known bug inherited from Scintilla, so it can't easily be fixed.  The FAQ I mentioned in that original thread, now at http://notepad-plus.wiki.sourceforge.net/FindReplaceNewlineHowTo , explains all the workarounds I know of.  I would forget trying to do it with regex.

         
        • Nobody/Anonymous

          Wait a second - the original problem here is with the start of line character (^), NOT newline (\n).
          I love N++ but not being able to do a simple search-and-replace on the start of line or end of line ($) is a killer for me. I do that sort of operation a lot, and I don't want to (or shouldn't have to) memorize cryptic regex expressions as a workaround for two of the most fundamental (and valid) regex expressions ^ and $.
          As a result, I've paid for and use EditPad Pro as my default text editor.

           
          • Matthew Twomey

            Matthew Twomey - 2008-08-20

            This still doesn't appear to work? Does anyone know if this will eventually be corrected? I realize there are work-arounds, but I flip back and forth between vi and notepad++ all day and it's frustrating having to use a workaround in notepad++ to do this basic thing.

            Basically the vi equivalnet of :%s/^/Put this at the beginning:/g

            Thanks

             
    • steakhacher

      steakhacher - 2007-07-11

      There may be a work around: you can try to use
      search ^(.)
      replace -\1

      But - will not be added to empty lines

       
      • Mieszko Lassota

        Mieszko Lassota - 2007-07-12

        try maybe:

        search ^(.|\n)
        replace -\1

        but this won't work if the \n is not supported... or you can try:

        search ^(.|$)
        replace -\1

        but you'll have to try it... (haven't done it myself)

         
    • Nobody/Anonymous

      What about search ^(.*)
      Replace -\1