Re: [exim] String expansion: reversing a domain name?

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Philip Hazel
Datum:  
To: Jakob Hirsch
CC: 'Exim-users'
Betreff: Re: [exim] String expansion: reversing a domain name?
On Wed, 16 Feb 2005, Jakob Hirsch wrote:

> Marc Sherman wrote:
>
> > Is it possible to reverse a domain name with Exim's string expansion
> > operators?
> >
> > EG: given input "foo.bar.baz.com", output "com.baz.bar.foo".
>
> If the number of components of the domain name is constant (e.g. always 4),
> you can do it with
> ${sg{some.sample.host.name}{\N([^.]+)\.([^.]+)\.([^.]+)\.([^.]+)\.?\N}{\$4.\$3.\$2.\$1}}.
> At least I don't know how else one could do that with regex, but I'm no expert
> for that.
>
> If you want to do it for any domain name I think you have to run some external
> script, like Tony already wrote.


You could probably do it with a regex for *up to* a fixed number of
components with a bit of ingenuity. In the replacement you'd have to
test each $1, $2, etc for being empty, and if not, insert a dot and the
relevant $x. I haven't tested this.

Or you could do it with some nested regex changes, again up to a fixed
number. Given a.b.c.d, turn it into b.c.d/a then into c.d/b/a then into
d/c/b/a then, finding no more dots, turn the slashes back into dots. Or
something. Not sure if this could actually be done, however.

-- 
Philip Hazel            University of Cambridge Computing Service,
ph10@???      Cambridge, England. Phone: +44 1223 334714.
Get the Exim 4 book:    http://www.uit.co.uk/exim-book