Page 1 of 1
Look-behind in macro
Posted: 2017-08-06 05:51:55
by branner
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
and replacing it with
The look-behind expression is able to recognize level-2 sub-items that begin with "a".
But when I construct a macro:
Code: Select all
Find and Replace '(?<=a\.\t)(.+?)$', '\1\nNEW LEVEL-2 "b" here', 'EaW'
it does not produce the expected results. Am I doing something wrong?
Re: Look-behind in macro
Posted: 2017-08-07 09:19:05
by Þorvarður
Hi Branner,
You say
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:
Find and Replace '(?<=a\.\t)(.+?)$', '\1\n', 'EaW'
or
Find and Replace @Text{(?<=a\.\t)(.+?)$$}, @Text<\1\n>, 'Ea'
Re: Look-behind in macro
Posted: 2017-08-07 10:31:05
by phspaelti
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.
Re: Look-behind in macro
Posted: 2017-08-07 12:58:36
by branner
Indeed, it now works as expected. I don't know what went wrong — sorry for the trouble!
Re: Look-behind in macro
Posted: 2017-08-09 10:11:52
by martin
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!