Menu

Using "^" in replace

Mangocrate
2009-07-21
2012-11-14
  • Mangocrate

    Mangocrate - 2009-07-21

    I am trying to switch from Textpad to Notepad++ and have hit a wall...

    I want to simply replace the start of the line (^) with something else.  In Textpad I could just put in ^ as the regular expression, and it would add my replacement to the start of each line.

    In Notepad++ I can't figure out how to insert text at the start of the line using the "^" - I've only seen examples like "^." which replaces the 1st character of the line with my replacement - but I want to retain the 1st character.

     
    • Mangocrate

      Mangocrate - 2009-07-22

      @cchris - The only way to make a zero-size selection is to hold down the alt key and click-drag - which is fine when your selection length is short, but I often work in the range of hundreds to hundred of thousands of lines, and without a pane split, this just doesn't work.

      @Nelson - only working on lines with text can be a problem - better to have something constant.
      It would be nice to have just a ^ implemented in the replace box - doesn't seem to be a reason to require replacing text with it - shell scripts/vi/etc work that way.

       
      • Fool4UAnyway

        Fool4UAnyway - 2009-07-22

        Let me try to make a wise-guy impression by fooling you.

        Move the cursor to the top of the document: Ctrl+Home.

        Use the Text FX Advanced Find/Replace Dialog to do almost all line( end)s.

        In the Find Field, enter:
        <Ctrl+Enter>

        In the Replace Field, enter
        <Ctrl+Enter>
        your_text_to_be_inserted_here_on_the_second_line

        Do UNcheck the Regular Expression mode and possibly Wrap and (In) Selection checkboxes.

        Find and replace all occurrences.

        Now you only still have to insert the text on the very first line yourself.

        Perhaps you should read the Wiki contents about (finding and replacing) newlines.

         
    • Nelson Rocha

      Nelson Rocha - 2009-07-22

      I guess this is a workaround, but anyway...

      Find: "^(.)" - this searches for the first caracter of the line
      Replace by: "MyText\1" - this places the text "MyText" just before the match.

      The only problem is for empty lines, no text is inserted...
      Hope this will help.

       
    • cchris

      cchris - 2009-07-22

      If you wish to insert fixed text, there is a simpler way: the column editor. Make a zero size selection spannning all the line starts at which you wish to insert, alt-c, enter text and apply.

      CChris

       
MongoDB Logo MongoDB