Search for a string that is not within quotes.

Have a problem? A question? This is the place for answers from other Express users.
Post Reply
MarioMilosevic
Posts: 10
Joined: 2008-10-14 12:50:18

Search for a string that is not within quotes.

Post by MarioMilosevic » 2009-06-12 08:22:41

I'm looking for a way to search for a string of letters that is NOT contained within quotes. Anyone know how to make this happen using powersearch?

Specifically, I want to find words in my document that end in "ing" but that are not part of dialog.

For example, in the following section:

"Where are you going?" I asked.
He pointed to the waterfall flowing over the rocks. "On the other side of that," he said.


I would want NISUS to find flowing but to ignore going.

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

Re: Search for a string that is not within quotes.

Post by martin » 2009-06-12 12:23:19

I think this is going to be quite difficult (or impossible) to do using PowerFind alone. You could however use a Nisus Writer Pro macro.. this should do it:

Code: Select all

$doc = Document.active
$matched = Array.new

# move to start of document
Select All
Select Start

# Find all words ending in "ing"
While Find Next '\w+ing', 'E-W'
	$selection = $doc.textSelection
	$isQuoted = false
	
	# only include if next quotation mark is an open quote
	If Find Next '(\s?)(["”“])', 'E-W$'
		If $2 == '”'
			$isQuoted = true
		ElseIf $2 == '"'
			$isQuoted = 0 == $1.length
		End
	End
	
	If ! $isQuoted
		$matched.appendValue($selection)
	End
	
	# restore ealier search location
	$doc.setSelection($selection)
End

If 0 == $matched.count
	Prompt "No 'ing' words found outside quoted text."
Else
	$doc.setSelections($matched)
End

MarioMilosevic
Posts: 10
Joined: 2008-10-14 12:50:18

Re: Search for a string that is not within quotes.

Post by MarioMilosevic » 2009-06-12 13:24:54

Hmmm. I don't have Pro, so I guess I can't implement this. But thanks for the effort. I appreciate it.

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Search for a string that is not within quotes.

Post by Kino » 2009-06-12 17:59:32

Hopefully this would solve the problem.

1. Create a new Character Style Not Within Quotes or something alike having a visible attribute, e.g. highlight colour.

2. Find All \w+ing\b (word ending with ing) in PowerFind Pro mode.

3. Apply Not Within Quotes style on all occurrences found.

4. Find All ".+?" (text enclosed by straight quote) or “.+?” (text enclosed by curly quotes) to find/select all text portion within quotes.

5. Set Where to In Selection and Find All \w+ing\b to find/select all \w+ing\b within quotes.

6. Format:Character Style:Remove Style to remove Not Within Quotes style from all occurrences found.

Now only words ending with "ing" not within dialog have Not Within Quotes style.

To remove Not Within Quotes style entirely from the document, just delete the style in the Style Sheet.

If you often do this kind of operations, I think you'd better upgraded to Nisus Writer Pro in which you could use Invert Selection macro.

Post Reply