Skip to content
TheChatArchiveThe Chat Archive
Human-written demonstration (OpenAssistant volunteers)· OpenAssistant (human-written)Hugging Face OpenAssistant Conversations (oasst2)

write a regex expression that find graphql queries or mutations in a file

In OpenAssistant data, “assistant” turns were written by human volunteers as demonstrations. They are not model outputs.
  1. User

    write a regex expression that find graphql queries or mutations in a file

  2. Assistant

    Certainly! Here's a regular expression pattern that can match GraphQL queries or mutations in a file:

    /\b(query|mutation)\b\s*(\w+)?\s*{[\s\S]*?}/g

    And here's an explanation:

    • "\b(query|mutation)\b" matches the keyword query or mutation as a whole word.
    • "\s*(\w+)?\s*" matches an optional identifier for the query/mutation (e.g. getUser).
    • "{[\s\S]*?}" matches the entire query/mutation block, including the opening and closing curly braces { and }.
    • The "/g" flag at the end of the pattern makes the expression match all occurrences in the input file.

    I hope that helps, and if not, don't hesitate to correct me!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.