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
Here is a regular expression (regex) pattern that can be used to find GraphQL queries or mutations in a file:
regex/\b(query|mutation)\b[\s\S]*?\{[\s\S]*?\}/gThis pattern uses word boundaries (\b) to ensure that only complete words "query" or "mutation" are matched, and it uses a non-greedy wildcard match ([\s\S]*?) to capture the entire query or mutation block, including the curly braces. The g flag at the end of the pattern enables global matching, which allows multiple queries or mutations to be matched within the same file.
This is a basic pattern that can be customized to match the specific syntax of your GraphQL queries or mutations, if necessary.
- User
Thanks. Can you modify it so that it only returns those without this list of profanities:
arsehole, ass, asshole, bastard, bitch, bloody, brotherfucker, bullshit, cock, cocksucker, crap, cunt, dick, dickhead, dyke, fatherfucker, fuck, goddamn, godsdamn, holy shit, horseshit, in shit, kike, motherfucker, piss, prick, pussy, shit, shit ass, sisterfucker, slut, son of a bitch, son of a whore, spastic, turd, twat, wanker
- Assistant
You can use a negative character class with those profane words to exclude matches that contain them: /\b(?:query|mutation)\b(?:[^\s\S]?['"]?(?:(?:arsehole|ass|asshole|bastard|bitch|...)[^'"]))[\s\S]?{[\s\S]?}/g
I added [^\s\S]? to allow any number of non-word, non-whitespace characters ('"`]) before the exclusion list, in case any of the profane words were part of longer words. The ... is just an ellipsis to represent the full list of excluded words you would insert.
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 →