[pmwiki-users] Need help writing a simple markup for IP addresses inside of pages
Chris Cox
ccox at airmail.net
Mon Oct 16 17:26:04 CDT 2006
Patrick R. Michaud wrote:
> On Sun, Oct 15, 2006 at 09:53:45PM -0500, Chris Cox 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]]%%');
>>...
>>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.
>
> The problem is that the replacement text "[[Network/Ip$1-$2-$3-$4|$1.$2.$3.$4]]"
> matches the original pattern in the part after the '|'. So, if the replacement
> rule gets called multiple times (as can happen if there are any PRR-based
> rules in the sequence), then it will be processed multiple times. The
> same goes for [[...|$1.$2.$3.$4.in-addr.arpa]].
>
> The trick is to make sure that the replacement can't re-trigger the original
> rule. One way to do it:
>
> Markup('IPAddy', 'inline',
> '/\\b(?<!\\|)(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\b/',
> '%newwin%[[Network/Ip$1-$2-$3-$4|$0]]');
>
> The (?<!\\|) is a "negative lookbehind" that says "don't match this pattern
> if the preceding character is a vertical brace".
>
> Similarly, do:
>
> Markup('IPRevAddy', '<IPAddy',
> '/\\b(?<!\\|)(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\.in-addr\\.arpa\\b/',
> '[[Network/Ip$4-$3-$2-$1|$0]]');
>
> Note that this second rule is set to be processed _before_ the 'IPAddy'
> rule, so that in-addr.arpa addresses are processed before the standard
> IP addresses.
You're the second person saying I need to escape the backslash. Why?
It seems to work without escaping it. Thanks for the tips.
More information about the pmwiki-users
mailing list