Millisecond Forums

validresponse regular expressions

https://forums.millisecond.com/Topic20979.aspx

By lwise - 3/6/2017

I'm looking for an easy easy syntax to specify a valid response for any combination of four x's and four o's (i.e. an 8 letter string containing exactly four x and o in any pattern, without iterating through the possible patterns. 

Thanks
Lisa
By Dave - 3/6/2017

lwise - Tuesday, March 7, 2017
I'm looking for an easy easy syntax to specify a valid response for any combination of four x's and four o's (i.e. an 8 letter string containing exactly four x and o in any pattern, without iterating through the possible patterns. 

Thanks
Lisa

You can specify a regular expression to match that pattern via an <openended>'s /mask attribute.
By Dave - 3/7/2017

Dave - Tuesday, March 7, 2017
lwise - Tuesday, March 7, 2017
I'm looking for an easy easy syntax to specify a valid response for any combination of four x's and four o's (i.e. an 8 letter string containing exactly four x and o in any pattern, without iterating through the possible patterns. 

Thanks
Lisa

You can specify a regular expression to match that pattern via an <openended>'s /mask attribute.

Alternatively, you can achieve a similar effect using /isvalidresponse and a couple of string functions:

<openended myopended>
/ charlimit = 8
/ isvalidresponse = [
    length(replaceall(tolower(openended.myopended.response), "x","")) == 4 &&
    length(replaceall(tolower(openended.myopended.response), "o","")) == 4
]
</openended>
By lwise - 3/7/2017

Perfect

Thanks so much for your prompt response

Lisa