Powerfind question

Everything related to our flagship word processor.
Post Reply
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Powerfind question

Post by xiamenese »

In case I need it for the future.

I have been editing the script for a video commentary. At the end of each paragraph I added an estimate of the time needed with (approx. ## secs), ## secs being the number of seconds of course.

Before sending the finalised script, I wanted to remove that parenthesis and thought I'd use Powerfind to search for that string and leave the Replace field empty. However in one of the paragraphs, my counterparts had — unnecessarily — included (IQC) in the text, so the search result was all of "(IQC) + three lines of blah. (approx. ## secs)".

As this was only one case in three pages of A4 it was easy to remove the (IQC) manually and continue with the replace. So my question is: is it possible to construct a Powerfind search that will find text like (approx. ## secs) while ignoring any other parenthesised text in a document? I can imagine situations where I would want to keep the equivalent of the (IQC) while removing the time estimates.

:)

Mark
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Powerfind question

Post by adryan »

G'day, Mark et al

Search is "greedy", meaning it will return the longest string that matches the Find conditions. I suspect you merely searched for text delimited by opening and closing parentheses, which was too broad a search, hence the over-inclusive result.

A more specific PowerFind search string would be:–

(approx. [AnyDigit][1+] secs)

where the bracketted expressions represent PowerFind expressions.

The PowerFind Pro equivalent would be:–

\(approx\. \d+ secs\)

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Powerfind question

Post by xiamenese »

Thanks Adrian,

Now why didn’t I think of that? :oops:

Basically, this is nearly my first excursion into the delights of Powerfind—PowerfindPro is another giant leap for this mere mortal!—so I was only thinking about wild cards.

Lesson learnt! :D

Mark
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Re: Powerfind question

Post by Vanceone »

If you have a problem and turn to regular expressions, usually you now have two problems.

Adryan is right about the greediness of Regular Expressions, which is what PowerFind and Powerfind Pro use. However, a question mark in the wrong spot in the wrong spot can turn off greedy regular expression parsing. Which can be very useful...or very inconvenient.

For your issue this won't matter, but for others reading this, be aware. Use PowerFind instead of Powerfind Pro if you can.
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Powerfind question

Post by adryan »

G'day, Vanceone et al

Allow me to advance an alternative perspective.

Apart from special contexts (as with some Internet search engines, for example), no matter what form of search you use, there is no room for error in framing your Find and Replace expressions. You have to pay scrupulous attention to syntax. In short, search is generally unforgiving.

In the case of PowerFind Pro, beginners can construct expressions using the options provided in the cogwheel drop-down menus which will employ question marks (et al), or not, as appropriate. With a little practice, you will soon get the hang of how to do a lot of useful stuff without having to resort to the cogwheel options.

My recommendation is to give PowerFind Pro a try. It may not look pretty, but you may find it's not as difficult as you thought. And it does have some advantages. Expressions are plain text which can be copied and pasted elsewhere as is. It is more powerful than PowerFind. And facility with proper regular expressions can prove useful in other applications (notably BBEdit and Terminal). So you are learning to use a more versatile and widely applicable "language".

As I say, an alternative view.

As always, you are strongly advised to test unfamiliar or complicated operations on a duplicate of your document, and not to rely on Undo to extricate you from any disaster that eventuates.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Powerfind question

Post by martin »

Vanceone wrote: 2021-03-11 21:11:37 Adryan is right about the greediness of Regular Expressions, which is what PowerFind and Powerfind Pro use. However, a question mark in the wrong spot in the wrong spot can turn off greedy regular expression parsing
That's exactly right. You can turn a greedy search into a lazy or non-greedy search by following a repetition operator with a question mark.

For example, the regex \(.+\) will match parenthesized text, but it will do so across sets of parentheses. It would undesirably find text like "(abc) to (123)" as a single match. You can add a question mark after the plus sign to use the regex \(.+?\) instead. That will match "(abc)" and "(123)" separately.

PowerFind in Nisus Writer uses the term "shortest" to describe these non-greedy patterns, eg: "1+ Shortest"
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Powerfind question

Post by xiamenese »

Thank you very much Martin. That's very helpful.

Thinking back, I have used PowerFind Pro for very simple search & replaces, such as searching for \n\t to replace it with \n in documents sent to me by Chinese students or colleagues with random tabs following newlines. But I feel I'm getting too old to start learning the arcana of RegEx code!

It never ceased to amaze me that a student could send me their CV/Resumé for me to check … a complete dog's dinner of formatting, sometimes a newline, sometimes a linefeed, sometimes a tab, other times a sting of spaces, random changes in font size … but always claiming to be expert in the use of Microsoft Word! :D

Mark
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Powerfind question

Post by martin »

xiamenese wrote: 2021-03-15 06:09:16 But I feel I'm getting too old to start learning the arcana of RegEx code!
Regex codes are arcane indeed 🧙🏻‍♂️ They're amazingly powerful, but hard to keep straight unless you use them often enough– just like most skills.
It never ceased to amaze me that a student could send me their CV/Resumé for me to check … a complete dog's dinner of formatting, sometimes a newline, sometimes a linefeed, sometimes a tab, other times a sting of spaces, random changes in font size … but always claiming to be expert in the use of Microsoft Word! :D
Documents like resumes can be a real horror, haha. I have no doubt that you get them all straightened out 🤓 It's nice to feel useful!
Post Reply