SCI_REPLACETARGETRE with CXX11REGEX?

110 views
Skip to first unread message

Patrick Kwong

unread,
Sep 19, 2016, 11:46:36 PM9/19/16
to scintilla-interest
Is it possible to have c++11 regex replace?
In my editor, I want to use SCFIND_CXX11REGEX for find. It would seem weird to use a different syntax for replace.
What were the considerations when adding c++11 regex to find and not replace?

Neil Hodgson

unread,
Sep 20, 2016, 6:22:18 PM9/20/16
to scintilla...@googlegroups.com
Patrick Kwong:

> Is it possible to have c++11 regex replace?
> In my editor, I want to use SCFIND_CXX11REGEX for find. It would seem weird to use a different syntax for replace.
> What were the considerations when adding c++11 regex to find and not replace?

What did you try and what happened?

Neil

Patrick Kwong

unread,
Sep 21, 2016, 1:05:01 AM9/21/16
to scintilla-interest, nyama...@me.com

   What did you try and what happened?


Suppose the text is 
hello world

I first called SCI_SEARCHINTARGET( "hello (.*)" ) with search flags (SCFIND_REGEXP | SCFIND_CXX11REGEX) to capture "world"
Then I called SCI_REPLACETARGETRE( "hi $1" ), expecting "hi world".
After checking with the doc, I found that I need to use \1 instead.
 

Wonson

unread,
Oct 5, 2016, 4:20:42 AM10/5/16
to scintilla-interest, nyama...@me.com
Neil,

Hi, is there any body fixing this?
I think $1 is also a valid regex syntax for it.

i suppose changing this line in SubstituteByPosition like below is already ok? 
if (text[j] == '\\' || text[j] == '$' )


Wonson

Patrick Kwong於 2016年9月21日星期三 UTC+8下午1時05分01秒寫道:

Wonson

unread,
Oct 5, 2016, 4:28:41 AM10/5/16
to scintilla-interest, nyama...@me.com
Hmm, seems not accurate enough. It may have to be

#ifndef NO_CXX11_REGEX
 
if (flags & SCFIND_CXX11REGEX)
   
//use c++ regex instead


:/ ?


Wonson於 2016年10月5日星期三 UTC+8下午4時20分42秒寫道:

Neil Hodgson

unread,
Oct 5, 2016, 4:07:53 PM10/5/16
to scintilla...@googlegroups.com
Wonson:

> Hi, is there any body fixing this?
> I think $1 is also a valid regex syntax for it.

Allowing a second syntax will cause unexpected behaviour in current applications. ‘$1’ and similar are used in various programming languages causing extra substitutions.

If you want a different replacement syntax then implement it in your application. The tagged strings are available with http://www.scintilla.org/ScintillaDoc.html#SCI_GETTAG

Neil

Patrick Kwong

unread,
Oct 6, 2016, 12:33:59 AM10/6/16
to scintilla-interest, nyama...@me.com

   Allowing a second syntax will cause unexpected behaviour in current applications. ‘$1’ and similar are used in various programming languages causing extra substitutions.

   If you want a different replacement syntax then implement it in your application. The tagged strings are available with http://www.scintilla.org/ScintillaDoc.html#SCI_GETTAG

   Neil


I agree about the unexpected behavior in current applications, could we have flags like search to specify the syntax used?

Neil Hodgson

unread,
Oct 10, 2016, 12:57:08 AM10/10/16
to Scintilla mailing list
Patrick Kwong:

> I agree about the unexpected behavior in current applications, could we have flags like search to specify the syntax used?

It seems more work to me to add it properly to Scintilla with an API (in .iface) and tests and documentation and all compared to implementing it in your application. If someone is prepared to do the work then it can go in.

Neil

Reply all
Reply to author
Forward
0 new messages