Reply to topic  [ 5 posts ] 
Look-behind in macro 
Author Message

Joined: 2017-08-06 05:33:06
Posts: 2
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?


2017-08-06 05:51:55
Profile

Joined: 2012-12-19 05:02:52
Posts: 226
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'


2017-08-07 09:19:05
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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.

_________________
philip


2017-08-07 10:31:05
Profile

Joined: 2017-08-06 05:33:06
Posts: 2
Indeed, it now works as expected. I don't know what went wrong — sorry for the trouble!


2017-08-07 12:58:36
Profile
Official Nisus Person
User avatar

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


2017-08-09 10:11:52
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 4 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