21

I am trying to move away from TextPad, and I just can't get regular expressions like ^ and $ to be replaced. I have definitely ticked the regular expression box.

What am I doing wrong?

I am trying to find the start of a new line. In TextPad, it is find '^' and ensure regular expressions is enabled. With Notepad++ it does not do that. It just says "Not found".

3
  • I've used TextPad and found this same issue to be annoying (to put it mildly). Basically, Npp's Regex functionality is stunted when comared to most other Regex-s. This stems from the fact that Npp is an abstraction of the Scintilla Editor which uses a single-line-based RegEx :( -- The Npp crew are quite well aware of this issue, but it has (oddly) been on the back-burner (a time and resources issue). $ does work, but they haven't got ^ to work multi-line (yet). I know this limitation, and work with (and aroud it). As mentioned below ^(.) works. (Rarely, I revert to TPad or UltraEdit)
    – Peter.O
    Aug 5, 2010 at 23:59
  • 1
    PS. you can often use Extended (vs RegEx ) as a workaround for \r and \n - this semi-mimics a start-of-line. Also, as a by-the-way, you can stay in Normal search and turn on View -- Show Symbol -- Show End of Line.. Although they don't (visually) appear in the Find-field, if you select CRLF first, the Find-field auto-prime kicks in when you press CTRL+F, and it quite happily becomes a multi-line (but not RegEx) search. Its not much different to Extended search, but I found it to be interesting, and some readers may also find it so. (I love Npp :)
    – Peter.O
    Aug 6, 2010 at 0:21
  • Why exactly are you trying to find the start of a new line? Do you want to add something at the beginning of every line? That would help us actually answer the question. If you are using Notepad++ in order to move away from a paid solution, you will have to learn its quirks and work around them. I have had no problem doing this, since Notepad++ is very good in so many other ways. Apr 20, 2016 at 6:48

6 Answers 6

28

^ and $ are both anchors in Regex, which means if you want to replace the literal chars ^ and $ you need to escape them, usually with a leading backslash (\^, and \$).

To find the first character on a line use ^.

The start line anchor (^) is a zero-width match, so combining it with the . will find any character at the beginning of a line.

Maybe you can explain what you're actually trying to do?

8

Because these are special characters that represent the front (^) and end of line ($). Try escaping them with a \.

Examples:

Match "Cat" at the beginning of the line:

^Cat

Match "Cat" at the end of line:

Cat$

Match "Cat" as only thing on a line:

^Cat$

Match a "$100" within a line:

\$100 

Here is a link for the specifics on regular expression matching within Notepad++.

1
  • 2
    The link seems to be (effectively) broken. Nov 1, 2012 at 1:50
7

I've had the same issue myself. After some trial and error you can achieve the same by doing the following:

Find: ^(.)

Replace: [the string you wish you insert]\1

What this will do is locate and tag the first character of the line, put in the new string and put the tagged character after it.

For example, I needed to insert a single quote at the start of each line:

Find: ^(.)

Replace: '\1

You can do the same for the end of the line by doing:

Find: (.)$

Replace: \1*[the string you wish to append]*

1

I got it.

Before

  • Albert@hotmail.com
  • Lucas@gmail.com
  • Rober_Klein@aol.com
  • Fisher@zmail.com

After

  • Albert
  • Lucas
  • Rober_Klein
  • Fisher

Remove after character or text

@(.*)$

Remove before character or text

^(.*)@

dot = any character
asterisk = zero or more times
1

Here is how to do it...

Before:

$_GET['id']; $_GET['nick'];

After:

htmlentities($_GET['id']); htmlentities($_GET['nick']);

So. On the find field put:

$_GET(.*])

On the replace field put:

htmlentities($_GET\1)
0

The issue seems to have been fixed now.

In Notepad++ v6.9.2 (running under Windows 7) I get both ^ (start of line) and $ (end of line) to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.