 |
SoftTree Technologies
Technical Support Forums
|
|
Author |
Message |
gemisigo
Joined: 11 Mar 2010 Posts: 2165
|
|
[SA 7.2.338 Pro] - Advanced Text Processor |
|
I was experimenting with Advanced Text Processor but I found no way forcing it to detect a regexp for a certain scenario.
There are PRINTs in a stored procedure that obstructs some php scripts so I decided to make them optional by adding 'IF @debug = 1' in front of PRINTs. First I tried "(?<!IF @debug = 1[\s\n\r]*)PRINT" but it turned out Negative lookbehind do not support repetitions or variable lengths inside. So I tried "IF @debug = 1[\s\n\r]*?PRINT" with "IF @debug = 1 PRINT" followed by a "(?<!IF @debug = 1 )PRINT" + "IF @debug = 1 PRINT" but it does not seem to work. Any hints on how to make it change its mind?
|
|
Tue Sep 01, 2015 9:52 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
Fri Sep 04, 2015 1:38 am |
|
 |
gemisigo
Joined: 11 Mar 2010 Posts: 2165
|
|
|
|
Magnificent, thank you very much. But it still does not solve the issue with lookbehind. The code might already be formatted this way:
 |
 |
IF @debug = 1
PRINT @table_structure
|
And then I'll end up with
 |
 |
IF @debug = 1
IF @debug = 1 PRINT @table_structure
|
EDIT:
It seems that I managed to accomplish it by turning them back to simple PRINTs first with
 |
 |
-- Find text
^(\s*)IF\s*@debug\s*=\s*1\s*PRINT
-- Replace text
\1PRINT
|
followed by
 |
 |
-- Find text
^(\s*)PRINT
-- Replace text
\1IF @debug = 1 PRINT
|
|
|
Fri Sep 04, 2015 2:31 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
Great. Glad you find a workaround for that.
I've got a suggestion from my team that the same result could be achieved simpler by using one rule and in a single pass, without a need to remove previous IF @debug = 1 PRINT first.
First rule could be simplified:
 |
 |
-- Find text
IF\s*@debug\s*=\s*1\s*PRINT
-- Replace text
\0
|
If there is already "IF @debug = 1" - just replace it with the same text - that's the \0 reference. In this case formatting of already masked statements will remain the same.
|
|
Fri Sep 04, 2015 8:30 am |
|
 |
gemisigo
Joined: 11 Mar 2010 Posts: 2165
|
|
|
|
Thank you, I'll modify it accordingly
|
|
Fri Sep 04, 2015 5:12 pm |
|
 |
|
|
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 vote in polls in this forum
|
|
|