Gatsby: regex not working in Graphql query: Invalid flags supplied to RegExp constructor

Created on 23 Aug 2020  路  2Comments  路  Source: gatsbyjs/gatsby

Description

Describe the issue that you're seeing.

I'm trying to use this ^(?!content\/blog).* in my query

 query {
      allMdx(
        filter: { fileAbsolutePath: { regex: "^(?!content\/blog).*" } }
      ) {
        edges {
          node {
            id
            frontmatter {
              slug
            }
          }
        }
      }
}

but it gives me this error

Invalid flags supplied to RegExp constructor 'blog).*'

I have tested the regex on https://regex101.com and it seems to work well there:

image

I don't know Regex not sure how the regex that I have can be made valid.

Thanks.

bug

All 2 comments

I am also using a filter and have put slashes around the regex, which is working fine. So try:

filter: { fileAbsolutePath: { regex: "/^(?!content\/blog).*/" } }

I am not sure, but maybe this helps.

@nisarhassan12 yes, you need to wrap it in slashes, almost like a fully formed javascript regex.

Thanks @karland!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

signalwerk picture signalwerk  路  3Comments

rossPatton picture rossPatton  路  3Comments

mikestopcontinues picture mikestopcontinues  路  3Comments

ghost picture ghost  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments