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

Chris Cox ccox at airmail.net
Mon Oct 16 11:24:50 CDT 2006


Dominique Faure wrote:
> 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]]%%');

Not exactly.

The two rules are VERY different, the octets are reversed.
However I need them to stop stepping on each other.

Right now it appears that the reverse address rule
gets invoked and the resulting string matches the rule
for forward addresses and it gets invoked.

Still not fixed.




More information about the pmwiki-users mailing list