How replace all instances of a single string with one value?

Everything related to our flagship word processor.
Post Reply
Posts: 8
Joined: 2016-01-26 11:37:43

How replace all instances of a single string with one value?

Post by Sccardais »

Is there a way to find all instances of a string consisting of spaces and punctuation marks and replace it with a single character? For example, if the three character string appears one or more times, replace it with a single character such as ^.

The three character string that I am searching on (space + * + space) does not occur a fixed number of times. In some lines, it occurs more or less times than the line above and / or below it.

Thanks in advance.

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

Re: How replace all instances of a single string with one va

Post by martin »

This is definitely possible using Nisus Writer's extensive PowerFind tools (aka: regular expressions, regex, grep). Basically the goal will be to construct an expression that matches the kind of text you described. There are a variety of ways you might go about that. I'll outline one below.

With the assumption that you haven't used our PowerFind tools yet, here's how you start using them in your searches:

1. In the Find dialog, just under the label "Find what", you'll see a button with a little gear icon. Click it.
2. A contextual menu will appear with a variety of categories.
3. Under each category you'll see a variety of matching tools, eg: entries like "Any Space". We call these PowerFind bubbles, but basically they serve to dynamically match different pieces of text. The "Any Space" bubble will match a single regular space, an em space, etc.
4. You can combine multiple PowerFind bubbles to build your find expression.

In the situation you described, you want to match text sequences that combine any number of spaces and punctuation marks. To do that we'll build a character set that includes those criteria:
charset.png (16.25 KiB) Viewed 1819 times
The "1+" bubble afterwards just means to match one or more of the thing directly beforehand– in this case one or more spaces or punctuation marks. If you used just that expression it probably wouldn't do what you want, because "1+" times will match just a single space. It sounds like you want to match only longer sequences.

To arrive at a final solution we'd need to know more about what you want to match. I see two potential options:

1. If you just want to match lines of text that contain nothing but those characters, then add some "special position" bubbles to match the start and end of line:
position.png (18.56 KiB) Viewed 1819 times
2. If you just want to match cases where you have three or more of these characters in a row, then replace "1+" with the "N-M" bubble. When you insert that bubble you can choose how many repetitions you'd like to match:
repeat.png (15.63 KiB) Viewed 1819 times
(Note: the underscore appearing in the above screenshot is a bug, it should just show 3 to 999 times)

I hope that helps. Please let me know if you have any questions.

Posts: 8
Joined: 2016-01-26 11:37:43

Re: How replace all instances of a single string with one va

Post by Sccardais »

Yes. It helped a lot.

Thank you.


Post Reply