Regular Expressions / RegEx
Regular expressions are characters used to define a search pattern. They can be used to enhance existing W2H functionality. Go here and select the cheatsheet on the left panel to learn how regular expressions can be built and used. The webpage allows you to build a regular expression underneath the expression header. You can input a variety of test cases below the text/test header separated by rows (press enter) to see which cases are included in or found by the regular expression.
Example #1: Validating that a participant selects a reminder to occur between 9am-9pm (inclusive)
. = any character except a line break
* = zero or more instances of the preceding character
| = “or”
The regular expression in the example above validates the union of four pieces of logic:
09:.* validates 09:00-09:59
1.:.* validates 10:00-19:59
20:.* validates 20:00-20:59
21:00 validates 21:00
Note: the regular expression as written validates many other non-numerical inputs such as 09:GD, etc., but because the input type is Time (see above) and is limited to numerical inputs, this is not a problem.
Example #2: Validating that a participant inputs a zip code that is 5 numbers ranging from 0-9:
[0-9]{5}
[0-9] = a char in range 0-9 (inclusive)
{5} = repeat the prior criteria 5 times
Example #3: Validating that a kit ID is either 6 digits or 6 digits with a space in the middle
(e.g., 012 293 or 012293):
[0-9]{3} ?[0-9]{3}
[0-9] = a char in range 0-9 (inclusive)
{3} = repeat the prior criteria 3 times
“ ?” = 0 or 1 spaces (? = match 0 or 1 of the preceding character, which in this case is a blank space)
Example #4: Validating DOB with the format MM/DD/YYYY:
^[0-9]{2}[/][0-9]{2}[/][0-9]{4}$
[0-9] = a char in range 0-9 (inclusive)
{2} = repeat the prior criteria 2 times
{4} = repeat the prior criteria 4 times
[/] = insert / symbol
^ . . . $ = complete match in a message (instead of partial match)