Bug 138489 - Search and replace with regex $1 deletes existing emphasis or italics Editing, Search Replace, Regular expressions
Summary: Search and replace with regex $1 deletes existing emphasis or italics Editing...
Status: RESOLVED DUPLICATE of bug 62603
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
6.4.6.2 release
Hardware: All macOS (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-25 13:24 UTC by Daniele
Modified: 2020-11-28 18:28 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments
Test case (23.64 KB, application/vnd.oasis.opendocument.text)
2020-11-25 13:26 UTC, Daniele
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniele 2020-11-25 13:24:52 UTC
Description:
When using a search and replace string such as this one:
(\s+)([—|–]|\-{1,})(\s*)(.*?)(\s*)([—|–]|\-{1,})
and replace the results with
–⁠$4⁠–
any emphasis or italics (ith happens both when italics/emphasis is the only formatting and when it is just a word which is in italics/emphasis) is gone and one finds a text in with the regular format instead.

Steps to Reproduce:
1. Create or upload the attached document with - word italicsword word -.
2. Use Regex (\s+)([—|–]|\-{1,})(\s*)(.*?)(\s*)([—|–]|\-{1,}) to find the instance.
3. Replace with –⁠$4⁠–

Actual Results:
Italics/emphasis is gone

Expected Results:
Italics and emphasis should remain since I do not want to change them.


Reproducible: Always


User Profile Reset: No



Additional Info:
If it is not a bug and meant to be working like this, maybe a "keep format" option could be added to the search and replace window since the change which occurs is not desired by the user. It does happen with other search and replace strings (quotes for example) (\s+)([—|“]|\-{1,})(\s*)(.*?)(\s*)([—|”]|\-{1,})
Comment 1 Daniele 2020-11-25 13:26:32 UTC
Created attachment 167564 [details]
Test case

This file has a number of instances which can be used to test what the bug states.
Comment 2 Justin L 2020-11-28 18:28:14 UTC
from https://bugs.documentfoundation.org/show_bug.cgi?id=62603#c15

> Regex is irrelevant - it happens without regex as well. Basically, Find/Replace
> applies the format of the first character across the entire replaced string.

But yes, I understand that you are pulling the "replace" out of your search string, so perhaps their could be a bit more intelligence built-in to also carry along the current formatting. But I fully expect that this just gets a string of text, and not a fragment of fully formatted Writer text.

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