To Bold all text between parentheses

Everything related to our flagship word processor.
Post Reply
aghazzawi
Posts: 4
Joined: 2018-12-01 13:09:40

To Bold all text between parentheses

Post by aghazzawi » 2018-12-20 07:51:50

I have a big file on Nisus Writer 3.0, and it includes a lot of words between parentheses , example: abcd (111) cdis (vfdfg). I want to change all the parentheses and the text in between to boldface. How can I do that? I tried Find and Replace Any, AnyText, AnyCharacter. All did NOT work.

This is the answer in Microsoft Word:
Press Ctrl+H to activate the Replace dialog.
Click More >>.
Tick the check box Use wildcards.
In the Find what box, enter \(*\)
Click in the Replace box.
Leave it blank, but next click Format > Font... at the bottom of the dialog.
Click on Bold, then click OK.
Click Replace All.

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

Re: To Bold all text between parentheses

Post by martin » 2018-12-20 08:45:07

There's a variety of ways to do this, but here's what I'd recommend: Set the Find panel mode to "PowerFind" and enter the following expression:
powerfind.png
powerfind.png (21.75 KiB) Viewed 5125 times
You can insert those grey bubbles using the button with the gear icon under "Find what".

Note: The repeat bubble "1+ Shortest" is necessary here (instead of just "1+" or "AnyText") because otherwise the match will be too "greedy" and match text between multiple sets of parentheses.

Once you have the find expression in place, click the Find All button. That will select all matches in your document text. Now click the document window to activate it, and then use whatever tools you normally prefer for formatting text, eg: the Format menu. Nisus Writer lets you format multi-part selections no matter how they were created

If you prefer to use regex (regular expressions) then you could instead use a pattern like this to select your text:
regex.png
regex.png (20.17 KiB) Viewed 5125 times

I hope this helps. Please let us know if you have any questions.

aghazzawi
Posts: 4
Joined: 2018-12-01 13:09:40

Re: To Bold all text between parentheses

Post by aghazzawi » 2018-12-21 05:49:31

Thanks you. It worked.
However, what is the way to know which "string" to use for different situations? For example, even if I figured out using 1+Shortest, I would not have guessed to precede it with AnyCharacter.

User avatar
phspaelti
Posts: 1015
Joined: 2007-02-07 00:58:12
Location: Japan

Re: To Bold all text between parentheses

Post by phspaelti » 2018-12-21 07:47:08

Hello aghazzawi,
aghazzawi wrote:
2018-12-21 05:49:31
However, what is the way to know which "string" to use for different situations? For example, even if I figured out using 1+Shortest, I would not have guessed to precede it with AnyCharacter.
That's a very good question. Unfortunately there is not really an easy answer. Here are some suggestions:
  • AnyCharacter is generally going to be your best bet in most cases
  • Try different ones and see if you can spot the difference. (Make sure to use Find Next.)
  • Try reading some books on the subject. A good first introduction is Joe Kissell's section on Find and Replace in "The Nisus Way". Even though that book was written for the mac classic version of Nisus that section is still mostly appropriate. (See the discussion here.)
Also in fact I have been trying to write my own introduction. Mine is really intended more for Macro writing in the current version of Nisus Writer, and it's very much a work in progress. But I'm going to go ahead and put a draft (of the section on Find) here, for anybody interested.
Attachments
Find and Replace.pdf
(189.27 KiB) Downloaded 131 times
philip

User avatar
phspaelti
Posts: 1015
Joined: 2007-02-07 00:58:12
Location: Japan

Re: To Bold all text between parentheses

Post by phspaelti » 2018-12-21 08:07:01

phspaelti wrote:
2018-12-21 07:47:08
AnyCharacter is generally going to be your best bet in most cases
Actually I take that back. This is something that I find a bit annoying about the Nisus Wildcards. The most common wildcard in Regex is '.'. This is actually AnyTextCharacter in Nisus. The AnyCharacter wildcard in Nisus is actually this monstrosity '(?:.|\n|\f)'.

Side question: Why the redundant '\f'? It works just the same if you write '(?:.|\n)'

Basically AnyCharacter finds both text characters and returns/newlines. I guess I understand why Nisus did that.
philip

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

Re: To Bold all text between parentheses

Post by martin » 2018-12-27 11:06:53

Thanks to Philip for posting that PDF on Find and Replace in Nisus Writer. It's nice how it starts with the easy stuff, but quickly gets to more exciting advanced features like back-references.

I would like to make clear that Nisus Writer's "PowerFind Pro" mode has full support for regular expressions (regex), using Perl language syntax. There are lots of resources out there that help explain and teach regular expressions. A quick Google search will turn up many more.

Vanceone
Posts: 143
Joined: 2013-05-03 07:06:31

Re: To Bold all text between parentheses

Post by Vanceone » 2018-12-27 12:30:58

Yes, Regex is nice.... though to be honest, if you have a problem and resort to Regex, it's almost certain that now you have two problems, as the saying goes....

Nice to have, but best avoided!

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

Re: To Bold all text between parentheses

Post by martin » 2019-01-04 13:30:55

Vanceone wrote:
2018-12-27 12:30:58
though to be honest, if you have a problem and resort to Regex, it's almost certain that now you have two problems, as the saying goes....
It's certainly a very funny saying. I also enjoy the jab that it's a "write only language" :drunk:

But really regex is an incredibly useful tool! There are situations where using regex is simply the fastest way for accomplishing an otherwise very difficult or time-consuming task. The ability to quickly use regex can be invaluable.

Post Reply