jump to navigation

Confluence Wiki – attachments macro filtering using a regular expression March 9, 2012

Posted by ficial in techy.

The Confluence wiki engine (by Atlassian) lets a user attach files to a wiki page. There’s a macro that can then be used in the code for that page to display a list of all the attachments to the page. One nice feature of that macro is the ability to filter the list using a regular expression – e.g. show only the attachments that contain the string ‘Carrot’ in the file name.

Here are a few things I figured out (by experimenting and by looking for examples elsewhere) about the particular regex engine that Confluence uses:

  • regexes in this system don’t use slashes or other characters to mark the beginning and end of the regex. E.g. if you’re used to regexes in other languages you’re probably familiar with something like ‘/pattern/’, but in Confluence it’s just ‘pattern’
  • To make an expression case insensitive (or use other modifiers), lead it with (?i) (or other modifiers – ‘(?sm)’). E.g. (?i)foo will match foo, Foo, fOo, etc.
  • To filter OUT a string use a repeated negative look-ahead. E.g. to show all the files on the pages EXCEPT the ones containing the string ‘resume’, use ‘(.(?!resume))*’ (this is not especially efficient in terms of processing, but the environment is not exactly high performance computing and the strings are small, so it works fine); combining this kind of negative filter with some other positive filter gets trickier


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: