nisus.com
https://www.nisus.com/forum/

Look-behind in macro
https://www.nisus.com/forum/viewtopic.php?f=17&t=6788
Page 1 of 1

Author:  branner [ 2017-08-06 05:51:55 ]
Post subject:  Look-behind in macro

I have a two-level Number List. The level-1 items are numbered 1,2,3,4 and the level-2 sub-items are numbered a,b,c,d. There is a sample file attached.

I want to automatically add a sub-item "b" after each sub-item "a'. I can do this manually with Powerfind Pro, finding

Code:
(?<=a\.\t)(.+?)$


and replacing it with

Code:
\1\nNEW LEVEL-2 "b" here


The look-behind expression is able to recognize level-2 sub-items that begin with "a".

But when I construct a macro:

Code:
Find and Replace '(?<=a\.\t)(.+?)$', '\1\nNEW LEVEL-2 "b" here', 'EaW'


it does not produce the expected results. Am I doing something wrong?

Attachments:
nisus_writer_question_abt_look-behind_in_macros_20170806_sample_file.rtf [19.16 KiB]
Downloaded 24 times

Author:  Þorvarður [ 2017-08-07 09:19:05 ]
Post subject:  Re: Look-behind in macro

Hi Branner,
You say
Quote:
it does not produce the expected results

Your Find and Replace code adds indeed a sub-item "b" after each sub-item "a", so I'm not sure what your problem is.
What are the "expected results" you're expecting?

Is it perhaps the additional text
NEW LEVEL-2 "b" here
which you don't want? If yes, then don't include it in the replace part. It should then look like this:

Quote:
Find and Replace '(?<=a\.\t)(.+?)$', '\1\n', 'EaW'

or
Quote:
Find and Replace @Text{(?<=a\.\t)(.+?)$$}, @Text<\1\n>, 'Ea'

Author:  phspaelti [ 2017-08-07 10:31:05 ]
Post subject:  Re: Look-behind in macro

I agree with Þorvarður. The macro gives the same result as doing the Find/Replace from the Find dialog for me. So I'm not sure what your think is going wrong.

A different problem which I really think Martin should have a look at, is that after this Find/Replace the selections are shifted. The first one is okay. The second starts at the dot of the auto-number and the third reaches even further back.

Author:  branner [ 2017-08-07 12:58:36 ]
Post subject:  Re: Look-behind in macro

Indeed, it now works as expected. I don't know what went wrong — sorry for the trouble!

Author:  martin [ 2017-08-09 10:11:52 ]
Post subject:  Re: Look-behind in macro

phspaelti wrote:
A different problem which I really think Martin should have a look at, is that after this Find/Replace the selections are shifted. The first one is okay. The second starts at the dot of the auto-number and the third reaches even further back.

Thank you for calling this out Philip. You're right that the selection is off after the replacement for some matches. I'll take a look, thanks!

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/