[pmwiki-users] Need help writing a simple markup for IP addresses inside of pages

Dominique Faure dominique.faure at gmail.com
Mon Oct 16 10:19:38 CDT 2006


On 10/16/06, Chris Cox <ccox at airmail.net> wrote:
> I have:
>
> Markup('IPAddy', 'inline',
> '/([0-9][0-9]*)\.([0-9][0-9]*)\.([0-9][0-9]*)\.([0-9][0-9]*)/',
> '%newwin%[[Network/Ip$1-$2-$3-$4|$1.$2.$3.$4]]%%');
>
> Which works fine.
>
> However on some pages I have references to in-addr.arpa addresses
> of the form:
>
> 1.2.20.10.in-addr.arpa
>
> So... I tried a markup rule like:
>
> Markup('IPRevAddy', 'inline',
> '/([0-9][0-9]*)\.([0-9][0-9]*)\.([0-9][0-9]*)\.([0-9][0-9]*)\.in-addr\.arpa/',
> '[[Network/Ip$4-$3-$2-$1|$1.$2.$3.$4.in-addr.arpa]]');
>
> However, the two rules DO step on each other.  I know there is some
> fancy way of doing conditional regexp... but I don't even know that
> kind of regexp is used by PmWiki in this case.
>
> For example, I tried changing IPAddy to:
>
> Markup('IPAddy', 'inline',
> '/([0-9][0-9]*)\.([0-9][0-9]*)\.([0-9][0-9]*)\.([0-9][0-9]*)[^.]/',
> '%newwin%[[Network/Ip$1-$2-$3-$4|$1.$2.$3.$4]]%%');
>
> Which is sort of a bad hack which tries to look for the trailing dot...
> but the NOT syntax [^.] doesn't even appear to work inside the
> expression.
>
> Anybody have a hint as to the best way of automatically locating
> IP and in-addr.arpa's with markup and turning them into links?
> Thanks,
> Chris
>

What about:

Markup('IPAddr', 'inline',
'/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\.in-addr\.arpa))?/i',
'%newwin%[[Network/Ip$4-$3-$2-$1|$1.$2.$3.$4$5]]%%');

Dom




More information about the pmwiki-users mailing list