We're sorry AsposeCloud doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.cloud

Regex Patterns in Search

I’m using the Node SDK and when passing in Regex expressions like “s/Thing I Want To Find With no case/gi” it doesn’t match. If I put a simple exact match in, this seems to work fine. How are REGEX patterns supposed to be formatted for search if we want case insensitivity, grouping, etc?

For example, my regex looks like:

/(.*String 1\n)|(($|\n)String 2\n)/gi Where I want to match “String 1” at a line end OR String 2 that is on a line by itself.


Please share your sample code and document. We will look into these and guide you accordingly.

Code for generating RegEx expression (including g for global and i for case insensitive match):

private generateRegExPattern(keywords: string[]) {
let pattern = '';
for (const keyword of keywords) {
  if (pattern.length <= 0) {
    // At the start, do something different
    pattern = '/(' + keyword + ')';
  } else {
    pattern += '|(' + keyword + ')';
  console.debug('Pattern now ---> ', pattern);
if (pattern.length > 0) {
  pattern += '/gi';
console.debug('Returned pattern: ', pattern);
return pattern;


Code utilizing the regex pattern:

const request = new SearchRequest({
    name: doc,
    folder: 'files/' + 'customer folder',
    pattern: pattern,

    .then((requestResult) => {
      console.log('Result of request: ', requestResult);
    .catch((error) => {

This will NEVER produce a match, even though I know the regex pattern matches in the document.



Thanks for sharing additional information. I have noticed the issue and logged a ticket(WORDSCLOUD-2159) for further investigation and rectification. We will keep you updated about the issue resolution progress within this forum thread.


We have investigated the issue and want to inform you that currently our API does not support regex expressions with embedded expression options like:


where gi - expression options.

At the moment, you may use an expression with no global options. For a case insensitive example:

(?i)Thing I Want To Find With no case(?-i)

However, we will support the global options in the near future and will notify you as well.