write a regex expression that find graphql queries or mutations in a file
- User
write a regex expression that find graphql queries or mutations in a file
- Assistant
To find GraphQL queries or mutations in a file, you can use the following regular expression:
/(query|mutation)\s*\{\s*[\w\s\(\)\:\,]+\s*\}/gThis regex will match text that starts with either query or mutation, followed by optional whitespace, an open curly brace {, optional whitespace, one or more characters (letters, numbers, whitespace, parentheses, colons, or commas), optional whitespace, and a close curly brace }. The g flag at the end is to perform a global search and find all matches within the file.
- User
show me how to implement this
- Assistant
Here's an example of how to implement the regular expression in JavaScript:
const regex = /(query|mutation)\s*\{\s*[\w\s\(\)\:\,]+\s*\}/g; const fileContents = ` query { getUser(id: 1) { name email } } mutation { createUser(data: { name: "John Doe", email: "john.doe@example.com" }) { id } } `; let match; while (match = regex.exec(fileContents)) { console.log(match[0]); }This will output:
query { getUser(id: 1) { name email } } mutation { createUser(data: { name: "John Doe", email: "john.doe@example.com" }) { id } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →