PennController for IBEX › Forums › Support › Combing text and regex in test.text() › Reply To: Combing text and regex in test.text()
June 7, 2021 at 12:04 pm
#7029
Keymaster
Hi,
Regular expressions (built either using /slashes/ like you do, or with the RegExp constructor) are not Strings in javascript, so you cannot just concatenate a string (row.prime) with a regular expression /\w+/). You can, however, pass a literal string to the RegExp constructor, 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