Question

SyntaxEditor Replace with Regex

Posted 3 months ago by Avatar Frederic Gregoire

Hello,

When using the SyntaxEditor, the FindNext and ReplaceNext methods of the "SyntaxEditor.ActiveView.Searcher" take an "IEditorSearchOptions".
These options take a PatternProvider, which, if specified, can handle regex operations. The FindNext handles these scenarios well, but the ReplaceNext only seems to take the ReplacePattern and insert it where a match is found.

For example, given the following text in the syntax editor:
      TEXT,INFO,1000

And the following search and replace options:
RegexPattern
FindPattern: (TEXT,.*),1000
ReplacePattern: $2,500

I'd expect the output result to be:
    TEXT,TOP,500

But instead, it is:
    $2,500

Is there a way to make this work using the same substitution rules with regex as .net?
https://docs.microsoft.com/en-us/dotnet/standard/base-types/substitutions-in-regular-expressions


Information The latest build of this product (2018.1 build 0340) was released 6 months ago, which was before this thread was created.

Comments (2)

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA

Hello,

I believe your replace pattern should be this instead:

$1,500

That says use the first captured group.  Does it work how you'd like with that?


Actipro Software Support
Posted 3 months ago by Frederic Gregoire

Should of tried with your prodiver before posting. The issue I was running into was with my custom provider. But I found the solution thanks to your proposal,

Thanks for the help!


Add a Comment

Please log in to a validated account to post comments.