Bug 138752 - regular expressions find with newline fails search
Summary: regular expressions find with newline fails search
Status: RESOLVED DUPLICATE of bug 108256
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.0.3.1 release
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-08 19:22 UTC by Eugene Miller
Modified: 2020-12-24 17:09 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Documetn where we're attempting to find & replace signature lines. (13.76 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2020-12-08 19:22 UTC, Eugene Miller
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Miller 2020-12-08 19:22:25 UTC
Created attachment 167989 [details]
Documetn where we're attempting to find & replace signature lines.

Find when searching for regular expressions with new lines doesn't work.
ref:https://help.libreoffice.org/6.2/en-US/text/shared/01/02100001.html

# Testcase
- Ctrl+H
- find: `__________________________\nDemo Author`
- [x] Regular Expressions
- click `Find All`

Expected result:
Highlights:
```
__________________________
Demo Author
```
Actual result:
Warning icon shows up in the find box.



# Testcase 2
- Ctrl+H
- find: `__________________________\pDemo Author`
- [x] Regular Expressions
- click `Find All`
Expected result:
Highlights:
```
__________________________
Demo Author
```
Actual result:
Warning icon shows up in the find box.

# Testcase 3
- Ctrl+H
- find: `__________________________\pDemo Author`
- [x] Regular Expressions
- click `Find All`
Expected result:
Highlights:
```
__________________________
Demo Author
```
Actual result:
Warning icon shows up in the find box.

# Testcase 4
- Select the text
```
__________________________
Demo Author
```
- ctrl + c
- ctrl + h
- ctrl + v
- find:`__________________________
Demo Author
` - please note where there are new lines it's actually displaying an arrow that points to the left, similar to what you'll see on the enter key.
- [ ] Regular expressions
- click `Find All`

Expected result:
Highlights:
```
__________________________
Demo Author
```
Actual result:
Warning icon shows up in the find box.


Suggested action either add a dialog that's something like this https://bugs.documentfoundation.org/show_bug.cgi?id=38261 or add a "multi-line" checkbox under the sign input and make the regex greedy/non-greedy to fix it.

The desired end result is to do this in python.  The code below works as expected. `\n` isn't finding new lines or paragraph breaks.
```
replace = document.createReplaceDescriptor()
replace.SearchRegularExpression = True
replace.SearchString = r"Pre\-Authorized\*\*\*\*(Pre\-Authorized[ \*]+)+\*\*\*Pre\-Authorized"
replace.ReplaceString = r""
document.replaceAll(replace)
```
Comment 1 Eugene Miller 2020-12-08 22:23:45 UTC
This code however doesn't notice the `\n` at the end.
```
replace = document.createReplaceDescriptor()
replace.SearchRegularExpression = True
replace.SearchString = r"Pre\-Authorized\*\*\*\*(Pre\-Authorized[ \*]+)+\*\*\*Pre\-Authorized\n"
replace.ReplaceString = r""
document.replaceAll(replace)
```
Comment 2 [REDACTED] 2020-12-09 12:31:29 UTC
(In reply to Eugene Miller from comment #0)

> 
> Find when searching for regular expressions with new lines doesn't work.
> ref:https://help.libreoffice.org/6.2/en-US/text/shared/01/02100001.html
> 

and this documentatioh states:

 \n in the Find text box stands for a line break that was inserted with the Shift+Enter key combination

and the provided sample document finalizes the line with a paragraph mark.

From my perspective: Not a bug, but documented behavior.
Comment 3 Eugene Miller 2020-12-09 17:08:27 UTC
Ok, so the bug I'm dealing with isn't this.  You can close this if you like. There are multiple testcases that are actually different bugs.

The issue is other things that are coming into play that makes it harder to understand what's going on.  I mean you have to read the documentation to understand that there really isn't a way to search across 2 paragraph markers and if there is it's not documented.

- Copy/paste into the "find" converts paragraph ends into shift+enter new lines.
- There doesn't seem to be an easy way to find paragraph ends & paragraph beginnings.  `^._[_]+\pDemo` works in the "Alt Find & Replace" extension but won't here.
Comment 4 Justin L 2020-12-24 17:09:00 UTC

*** This bug has been marked as a duplicate of bug 108256 ***