Re: [code] Regular expression idiosyncrasy

From: Mitchell <m.att.foicica.com>
Date: Thu, 26 Oct 2017 10:15:05 -0400 (EDT)

Hi Danny,

On Wed, 25 Oct 2017, Danny MacMillan wrote:

> On 2017-10-25 15:45, Danny MacMillan wrote:
>>
>> I'm a little confused by how textadept does regular expression search
>> and replace. Suppose I have a file with these contents this:
>>
>> apples
>> oranges
>> bananas
>>
>> And I do a regular expression search and replace:
>>
>> Find: ^(.*)$
>> Replace: I like \1 ... I really like \1
>>
>> This is what textadept gives me:
>>
>> I like apples
>> ... I really like apples
>> I like oranges
>> ... I really like oranges
>> I like bananas ... I really like bananas
>>
>> But this isn't what I would ever want. In the tool I used to use, the
>> $ matches the end of the line which prevents .* from matching it.
>>
>> Is there a way to get this to work the way I want? in case it's not
>> clear, the newlines preceding the ellipses are unwanted.
>
> The TRE documentation for the REG_NEWLINE flag states:
>
>> When this flag is used, the newline character ('\n', ASCII code 10) is
>> treated specially
>
> Since they are quite explicit about their definition of what constitutes a
> newline, I turned on visible line ending characters and ran my replace again.
> This is what it's actually doing.
>
> apples<CR><LF>
> oranges<CR><LF>
> bananas
>
> ... becomes ...
>
> I like apples<CR>
> ... I really like apples<CR><LF>
> I like oranges<CR>
> ... I really like oranges<CR><LF>
> I like bananas ... I really like bananas
>
> The issue clearly is that the regular expression engine doesn't accommodate
> anything other than Linux-style line ending characters, and I'm using
> Windows.
>
> I don't quite know what to do about this. It doesn't seem like something I
> can work around with anything I put into Lua. Any ideas?

Thanks for the report and for taking the time to investigate this. I've committed a patch[1] for Textadept's TRE library that should handle this. It will be in the next nightly build.

Cheers,
Mitchell

[1]: https://foicica.com/hg/textadept/rev/39a7079f29e8

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Thu 26 Oct 2017 - 10:15:05 EDT

This archive was generated by hypermail 2.2.0 : Fri 27 Oct 2017 - 06:46:23 EDT