Re: [code] Regular expression idiosyncrasy

From: Danny MacMillan <foicica.att.nekulturny.org>
Date: Wed, 25 Oct 2017 18:52:14 -0600

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?

-- 
Dan
-- 
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 Wed 25 Oct 2017 - 20:52:14 EDT

This archive was generated by hypermail 2.2.0 : Thu 26 Oct 2017 - 06:45:47 EDT