How To Use Wildcard as the First Character of a String on Confluence Search

Still need help?

The Atlassian Community is here for you.

Ask the community

Use Cause

  1. User wants to search for pages/attachments using a wildcard at the beginning of the string.
  2. User wants to search for pages/attachments that mention specific URLs without using the exact URL.

 

Example: 

http://dev.example.com/
dev-no-http.example.com

 

 

Resolution

Considering the same domains mentioned above, when we perform the search we need to be exact or use wildcards. However, Lucene does not support wildcard at the beginning of the word being searched (see documentation and CONF-32846 - Getting issue details... STATUS ).

Having that in mind, we'd have the following alternatives:

Alternative 1
http\:\/\/dev.example.com*
  • Here we are escaping the special characters with a backslash before the special char. Then, instead of using the / at the end, we are using a wildcard symbol: *

From Lucene Documentation (here):

Escaping Special Characters

Lucene supports escaping special characters that are part of the query syntax. The current list special characters are

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /

To escape these character use the \ before the character. For example to search for (1+1):2 use the query:

\(1\+1\)\:2

 

Alternative 2
"http://dev.example.com/"
  • Here we use the exact term, which returns the expected results.

 

Alternative 3
 /http:\/\/dev.example.com\//
  • Lucene supports regular expression searches matching a pattern between forward slashes, so we can escape the special characters and use the slashes to find the text as well.

See this Lucene documentation (here):

Regular Expression Searches

Lucene supports regular expression searches matching a pattern between forward slashes "/". The syntax may change across releases, but the current supported syntax is documented in the RegExp class. For example to find documents containing "moat" or "boat":

/\[mb\]oat/

 

Alternative 4
/.*http:\/\/dev.example.com.*/
  • Then, we can escape the special characters again and use wildcard along with the slashes from the alternative 3. This will work as a wield card to search the pages/attachments that contain the text we're looking for, but will not search for the exact text.

 

Alternative 5
/.*dev.example.com*./
  • This works just as alternative 4, but the wildcard works for text before "dev" and after "com".

 

Alternative 6
/.*dev.example.com*./ OR "http://dev.example.com/"
  • This would perform the search for pages/attachments containing dev.example.com and the exact text.

 

Last modified on Feb 26, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.