Query pages that match a url pattern

I need to query all the pages matching a specific path but I can’t make it work. I’ve tried a couple of different query options but it either brings no results or all the results without filtering. Here’s a couple of the options I’ve tried.

No results

{
    options: {
      noTargeting: true,
    },
    fields: 'data,name',
    query: {
      data: {
        url: { $regex: '^/industry*' },
      },
    },
  }

Returns all pages without any filters

{
    options: {
      noTargeting: true,
    },
    fields: 'data,name',
    query: {
      'data.url': /\/industry*/,
    },
  }
{
    options: {
      noTargeting: true,
    },
    fields: 'data,name',
    userAttributes: {
      urlPath: '/industry*',
    },
  }

Any suggestion on how could I archive this?

Hello @luchesigui,

Welcome to the builder.io forum post.

You may find help on using $regex operator at the below forum post

@manish-sharma thank you for your answer but I didn’t help much. I have no problem with using the $regex operator. I tried with name, for example, and it worked, but it seems that the URL has something special on it, because it doesn’t work.

Hello @luchesigui,

Indeed, it’s a known issue with targeting URLs. The solution provided below works. Therefore, you may need to consider targeting another field or creating a custom field that you can target to obtain the desired result.

  const pages = await builder.getAll('page', {
    options: { noTargeting: true },
    omit: 'data.blocks',
    query: {
      'data.title': { $regex: '^testing.*' },
    },
  })

Hum… I see, but the only thing the pages have in common is their URL. So the only option is whether to create a new field duplicating the URL information or something like that, or bring all the data and filter it on my application. Okay, then.

Is there anything planned that may change this in a short period of time? (next quarter or so)

Hello @luchesigui,

The dynamic nature of the URL presents some limitations when targeting them. However, I want to assure you that we have plans to address this issue in upcoming updates. Additionally, I will keep you informed and provide updates if there are any workarounds or solutions available to query them.