Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 201251

Summary: [find/replace] pattern ^$ does not match empty line.
Product: [Eclipse Project] Platform Reporter: Piotr Zielniok <griff>
Component: TextAssignee: Platform-Text-Inbox <platform-text-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: minor    
Priority: P3 CC: daniel_megert, gillis+eclipse, mcfeber
Version: 3.3Keywords: helpwanted
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Piotr Zielniok CLA 2007-08-27 09:08:04 EDT
Build ID: search/repalce - pattern ^$ does not match empty line

Steps To Reproduce:
1. Make empty line in editor.
2. Try to search for it (fine/replace with regular expression check box checked)


More information:
Comment 1 Dani Megert CLA 2007-08-27 09:42:06 EDT
Can reproduce with 3.4 M1.
Java regex supports this.
Comment 2 Mark Feber CLA 2009-09-25 17:35:28 EDT
The code appears to be returning an improper response at line 233 in org.eclipse.jface.text.FindReplaceDocumentAdapter findReplace(....)

if (found && fFindReplaceMatcher.group().length() > 0)
 return new Region(fFindReplaceMatcher.start(),
                   FindReplaceMatcher.group().length());
return null;


When ^ or $ is found by the java Matcher on regex search, the length of the group will be 0 as the offset in the Matcher's group[0] and group[1] will be the same location - but not -1.  

Unless there is some other downstream (or upstream) reason for the null return on ^ or $, this code should be changed
Comment 3 Dani Megert CLA 2009-09-28 10:59:27 EDT
The problem when fixing it there is
- we cannot select invisible characters ==> the caret will disappear
- Find Next will not work
Comment 4 Gillis J. de Nijs CLA 2011-03-29 07:04:22 EDT
Something similar happens when you replace.

^(.*)$ => PRE\1POST doesn't work.  It never matches.  The expected result would be PREPOST for empty lines.
Comment 5 Lars Vogel CLA 2019-11-08 04:38:44 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

If the bug is still relevant please remove the stalebug whiteboard tag.