Follow

Guide to: Regular Expression with Test Questions

 Regular expressions (regex) can be used to create flexible criteria for test questions for cml:text and cml:textarea fields. This attribute allows any response that contains the phrase set in the test question answer to be accepted in a text field. This can be especially useful when collecting urls or phrases.

 

How to set up regex for textbox field's test questions.

1. Set the following regex attributes

Screen_Shot_2018-08-09_at_12.56.37_PM.png

label: The question the contributor will see

name: The column header in the results file

src: This will be the name attribute with "_gold" appended to it in reference to the test question field it is being matched against.

regex: The value of this attribute is the regular expression that a correct response should satisfy. Using {seed} attempts to match the test question response from the contributor to the regular expression used.

flags: This attribute can be used to set modifiers that will change the behavior of the regular expression. Currently, there are two values that are accepted.

  • flags="i" - Makes the regex insensitive to case.
    • For example, if the test question answer is set to 'denim jacket' but 'Denim jacket' is submitted, the capital D will not cause the match to fail. 
  • flags="m" - When expecting to receive multiple line responses, the 'm' flag will ensure that the entire response is evaluated. This is essential for copy/ paste jobs.

Note: to utilize both flags simultaneously, use flags="im"

no_escape This attribute is used to read any special regular expression characters that are used. For example, "|" would be read as a regex character instead of a string with this value set to true.

 

2. Add the test question answers in the test question creation interface:

Screen_Shot_2018-08-09_at_12.56.32_PM.png

With the regular expression used above a contributor could input "https://www.levi.com/US/en_US/search/denim%20jacket" or "http://www.levi.com/GB/en_GB/search?Ntt=distressed+denim+jacket" and be marked correct. 

Note: when using ".+" there must be at least 1 character between the accepted words for the answer be matched. 

creating test questions can be done as usual, however, be conscious of using regular expression special characters and escaping characters if needed. 

Note: This also can be set up via the Test Question report. If the regex text field is name 'product_url'. In the test question report, add'product_url_gold'as the column header and populate it with the phrase or pattern to match for each unit.

 

For help writing your regex please reference this article


Was this article helpful?
3 out of 3 found this helpful


Have more questions? Submit a request
Powered by Zendesk