Re: [exim] Regex String Help

Página Principal
Apagar esta mensagem
Responder a esta mensagem
Autor: David S. Madole
Data:  
Para: Marc Perkel, exim
CC: 
Assunto: Re: [exim] Regex String Help
From: "Marc Perkel" <marc@???>
>
> OK - I don't know if this can be done but suppose I have a string with
> a number of items in it that are separated by spaces - and I want to
> remove all duplicate items for the string. Is there an easy way to do
> that?
>
> Example string:
>
> X-Sender-Nameserver: ns1.libero.it ns2.libero.it - ns1.libero.it \
> ns2.libero.it - mx2.libero.it mx3.libero.it mx4.libero.it mx5.libero.it
> \
> mx1.libero.it - mx2.libero.it mx3.libero.it mx4.libero.it mx5.libero.it
> \
> mx1.libero.it - -


How about this?

${sg{${sg{
$h_X-Sender-Nameserver }{\N\s(.*?)(?=\s.*\s\1\s)\N}{}}}{\N^\s|\s(?=\s)|\s$\N}{}}

Note that the literal spaces before and after the input data are
important!

With your example data:

# exim -be '${sg{${sg{ ns1.libero.it ns2.libero.it - ns1.libero.it
ns2.libero.it - mx2.libero.it mx3.libero.it mx4.libero.it mx5.libero.it
mx1.libero.it - mx2.libero.it mx3.libero.it mx4.libero.it mx5.libero.it
mx1.libero.it - - }{\N\s(.*?)(?=\s.*\s\1\s)\N}{}}}{\N^\s|\s(?=\s)|\s$\N}{}}'

ns1.libero.it ns2.libero.it mx2.libero.it mx3.libero.it mx4.libero.it
mx5.libero.it mx1.libero.it -

If you don't mind extra leading, trailing, or doubled spaces in the
output, the outer ${sg can be omitted.

I have this nagging feeling that I could do it just a little bit tidier,
but it's escaping me right now. But this works.

David