Currently, I'm using something like this to generate a list of pages whose prefix is "Prefix:" and link to them: {velocity}} ((( #foreach ($row in $services.query.hql("select doc.name, doc.fullName from XWikiDocument doc where doc.space.hidden = false and doc.space not in ('XWiki', 'Sandbox', 'Main', 'Macros') and doc.name like 'Prefix:%'").execute()) * **[[$row[0].replaceFirst("Prefix: *", "").replaceAll("~", "~~~~").replaceAll("[\x20-\x7f&&[^a-zA-Z0-9 ~]]", "~~$0")>>doc:$row[1].replaceAll("~", "~~").replaceAll("[\x5b\x5d|]", "\\$0 <file:///\\$0> ")]]** #end ))) {{/velocity}} I have tested with some heavy test cases like Prefix: ~~~!!!```@@@$$$%%%^^^&&&***((()))___----+++==={{{}}}[[[]]]\\\|||:::;;;'''""" ???///...>>>,,,<<< And what I have above works correctly (both showing the title and linking to the document). I only work on a few hard test cases, though, so I'm not sure if I missed anything. Is there a method that does all this automatically? Or is there a better approach to this?