Word And Sentence Requirements Regex For Google Forms

Viewed 77

I'm a teacher and I've been using regex on my google forms to eliminate some of the more nonsensical responses and to make grading easier. Easier grading equals a more fair teacher, so yeah.

Currently, I've got the google form regex set to "Doesn't Contain" and it looks something like this:

don't know|dont know|read about|video|i know|I know|do not remember| ah |ran out of time|i dont know|Blooket|blooket| assumption |chance|guess|studied|educated guess|remember reading|in the unit|annotations|I didn't know|guessed|asdf|sucks|I read it|i read it|I don't know| |classcraft|n/a|idk|i don't know|i don’t have any|guess|not sure|I studied|i studied|quizlet|this is stupid|this is dumb|^\s*(?:\S+(?:\s+\S+){0,48}\s*)?$

It works great! This particular one is used on their tests for their writing response question. It makes sure that they write at least 50 words, and it won't let them use certain phrases. As students get more and more clever with their workarounds, I just add them to the regex and future students can't do that.

I would really really like to be able to add another bit to it that would do two things. I want it in addition to what it already does, to:

  1. Identify what a sentence is. For these purposes (it can't be too restrictive as I work with students at times that have large gaps in their education) a sentence would be defined as beginning with a space and then a capital letter. A sentence would also always end with either a .!?"

  2. Set a minimum requirement for how many sentences must exist. I need to be able to set it to a one-sentence requirement, or a three-sentence requirement. Ideally, I could set it to be more than that too for future-proofing.

I don't really know what I'm doing with regex. I've kind of stumbled my way into a working version with the word requirements and I don't want to break what already works. Ideally, I could just add in a bit more to what I already have working to satisfy the sentence requirements.

Also, I know that regex isn't going to be able to do this perfectly. Like there are reasons why there might be a period in the middle of a sentence for example. But that's something that I can coach my students to not do. For the purposes of my class, I can curate the prompts so that a period, etc in the middle of a sentence wouldn't be appropriate anyways.

Any help would be greatly appreciated!

1 Answers

I am sorry that your question has not been answered sooner.

You have probably forgotten, and it is the summer, still, I have spent time working on this.

([^\s\n]+[a-zA-Z\s\d]{20,}[.?!\s\n]+){10,}

Or, with flags

/([^\s\n]+[a-zA-Z\s\d]{20,}[.?!\s\n]+){10,}/gm

It works by checking if the sentence starts with the characters in the first brackets.
The {20,} means 20 or more characters. You can remove this, or edit it to set the minimum characters in a sentence.

Next, it checks if the sentence ends with either . or ? or ! or space, or newline.
Finally, the {10,} is meant to be the minimum amount of sentences.
Change this to the minimum amount of sentences you want your students to need.

Test: here
Also, this is must include, not don't include, as not including non sentences is too hard to do.

Related