Search in "Find in files" result

Post here questions and problems related to editing and publishing DITA content.
JDL_CYT
Posts: 2
Joined: Tue Mar 23, 2021 4:33 pm

Search in "Find in files" result

Post by JDL_CYT »

Hello,

I'm not comfortable with xml, other than just writing in author mode so please keep it simple ;)

I need to exchange the word "dialog" to "dialog box" in multiple places in my bookmap. However, I also have entries that are already correct, i.e. "dialog box". If I do a find and replace all, the outcome in some cases will be "dialog box box". So far, I have gone from there and replaced "box box" with just "box".

When doing a search and replace in files, a tab with the findings appear (all my "dialog" hits), and in this list, files can be removed (those already correct "dialog box"). I was hoping I could start from this list (the one with "dialog box" removed), and replace only the entries that are left. Is there a way to do that?

Thanks in advance!
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Search in "Find in files" result

Post by adrian »

Hello,

The preview of the Replace in Files allows you to uncheck some of the files from the list. So, if the file granularity is fine, than sure, it can be done that way. But note that if you have files where both "dialog" and "dialog box" appear, you can't fix it.

It is actually possible to search for both "dialog" and "dialog box" whichever occurs (largest match) with the help of a regular expression.
Find: dialog( box)*
Replace with: dialog box
[x] Regular expression
( box)* means the space and box are optional.
This ensures that "dialog box" and "dialog" are replaced with "dialog box".

It's also possible to search for "dialog not followed by box". It can be done like this:
Find: dialog(?! box)
Replace with: dialog box
[x] Regular expression
Where (?! box) means not followed by space and box.
So, this replaces "dialog not followed by box" with "dialog box".

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Search in "Find in files" result

Post by chrispitude »

Hi JDL_CYT,

Here is a webpage where you can play around with regular expressions. I put Adrian's second example in the fields for you.

https://regex101.com/r/YAHVVF/1

- Chris
JDL_CYT
Posts: 2
Joined: Tue Mar 23, 2021 4:33 pm

Re: Search in "Find in files" result

Post by JDL_CYT »

Thank! I will try those!
:D
Post Reply