Regular expression (RegEx) search queries are universal and very flexible, but at the same time, in large indexes, their performance becomes extremely low. Another limitation of regular expressions is that search with a pattern is done for each word separately, and not the entire text of a document field.
Queries of this type always starts with the caret character, and if the regular expression itself also starts with the caret character, then there will be two caret characters at the beginning of the query.
The following example demonstrates the regex search in text and object forms.
StringindexFolder="c:\\MyIndex\\";StringdocumentsFolder="c:\\MyDocuments\\";// Creating an index in the specified folder
Indexindex=newIndex(indexFolder);// Indexing documents from the specified folder
index.add(documentsFolder);// Search for the phrase in text form
Stringquery1="^^(.)\\1{1,}";// The first caret character at the beginning indicates that this is a regular expression search query
SearchResultresult1=index.search(query1);// Search for two or more identical characters at the beginning of a word
// Search for the phrase in object form
SearchQueryquery2=SearchQuery.createRegexQuery("^(.)\\1{1,}");// Search for two or more identical characters at the beginning of a word
SearchResultresult2=index.search(query2);
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: