[Pmwiki-users] Another regexp-tip

Patrick R. Michaud pmichaud
Tue Jan 20 12:32:28 CST 2004


On Tue, Jan 20, 2004 at 05:07:33PM +0100, Christian Ridderstr?m wrote:
> and there's an interesting part about 'Assertions', e.g.
> 
> 	... "foo(?!bar)" matches any occurrence of "foo",
> 	 that is not followed by "bar".
> 
> Going back to the discussion on not allowing '@@' in URIs, maybe that's a 
> simple matter or adding "(?!@@)" which would prevent matching of "@@" at 
> the end.

Sorry, this is a common mistake made about lookahead assertions.  The 
assertion here doesn't say that the pattern can't end in @@, it simply 
means that the two characters that follow the matching part of the pattern 
cannot be '@@'.  For example, the pattern 

    "/(http:[^\s]*)(?!@@)/"

says to match "http:", followed by any sequence of non-space characters,
and make sure that the next two characters that follow are not "@@".
Given a string such as

    Please visit @@http://www.pmichaud.com/@@ for more information

the pattern will still match 'http://www.pmichaud.com/@@' because the
two characters that follow the matched portion are ' f' (i.e., not '@@').

Pm



More information about the pmwiki-users mailing list