PennController for IBEX › Forums › Support › Combing text and regex in test.text()
- This topic has 2 replies, 2 voices, and was last updated 5 years ago by
grusha.prasad.
-
AuthorPosts
-
June 7, 2021 at 11:32 am #7024
grusha.prasadParticipantHi,
I want to run a sentence completion experiment where participants are presented with a partial sentence and their task is to re-type the prompt and complete the sentence. Before allowing participants to continue to the next prompt, I want to check that they have typed out the prompt correctly along with at least one other word. Right now I have something like the code below and it does not let me progress. If I replace the regex with ” ” , then it does let me progress when I repeat the prompt and insert a space after. Similarly if I have just the regex, it lets me progress as long as I type a single word. Could you please point out what I am doing wrong? Thank you!
newText("Prime", row.prime) .settings.center() .print() , newVar("RT_prime").global().set( v_prime => Date.now()) , newTextInput("response") .print() , newButton("continue", "Next prompt") .settings.center() .settings.log() .print() .wait( getTextInput("response").test.text(row.prime+/\w+/) ) .remove()June 7, 2021 at 12:04 pm #7029
JeremyKeymasterHi,
Regular expressions (built either using
/slashes/like you do, or with theRegExpconstructor) are notStrings in javascript, so you cannot just concatenate a string (row.prime) with a regular expression/\w+/). You can, however, pass a literal string to theRegExpconstructor, which it will interpret as a pattern to build the regular expression:getTextInput("response").test.text( new RegExp(row.prime+"\s+\w+", 'i') )(I added\s+to require at least one space after the prime, and used'i'to make it case-insensitive, assuming it shouldn’t matter whether the participant uses upper- or lower-case)Jeremy
June 7, 2021 at 12:26 pm #7032
grusha.prasadParticipantThank you so much for the quick and helpful response! Just a note in case someone sees this in the future: I had to replace
"\s+\w+"with"\\s+\\w+". But once I did that, this worked perfectly. -
AuthorPosts
- You must be logged in to reply to this topic.