Reply to topic  [ 3 posts ] 
How replace all instances of a single string with one value? 
Author Message

Joined: 2016-01-26 11:37:43
Posts: 2
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.

2016-01-26 11:46:35
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
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 849 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 849 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 849 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.

2016-01-26 15:48:50
Profile WWW

Joined: 2016-01-26 11:37:43
Posts: 2
Yes. It helped a lot.

Thank you.


2016-01-27 03:59:59
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: Google [Bot] and 10 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software