Request for help: regular expression to test the FIRSTNAME token's value

More
5 years 9 months ago #71222 by guelphpeter
guelphpeter created the topic: Request for help: regular expression to test the FIRSTNAME token's value
Apologies if this is a newbie question:

I would like to place a condition on a question that says: only show this question if the letter "a" is in the token value for FIRSTNAME. I'm pretty sure I would need a regular expression to do this - something like below that tests to see if the letter "a" is in the string "we want to match something":

$regex(we want to match something,a)

What I don't know is how to construct the expression so the string being tested is the value of the "FIRSTNAME" token from the token table.

Thanks in advance for any help.

Peter

Please Log in to join the conversation.

More
5 years 9 months ago #71226 by TMSWhite
TMSWhite replied the topic: Request for help: regular expression to test the FIRSTNAME token's value
guelphpeter-

In 1.92 , you would set the relevance equation for that question to:
regexMatch("[aA]",TOKEN:FIRSTNAME)

For 1.91+, it is possible to set conditions using regular expressions, but I don't recall the details of how to do it.

/Tom

Please Log in to join the conversation.

More
5 years 9 months ago #71232 by guelphpeter
guelphpeter replied the topic: Request for help: regular expression to test the FIRSTNAME token's value
Thanks so much for your reply Tom. 1.92 looks very promising !

In 1.91 I tried just using:

("[aA]",TOKEN:FIRSTNAME)

for the condition but it did't work (i.e. the question is not displayed even though the FIRSTNAME attribute contains an 'a').

I'm afraid regular expressions are a bit beyond me, so there may well be a simple way to do this in 1.91 and I'm too much of a newbie to figure it out. If anyone has a suggestion I'd be grateful.

Thanks,

Peter

Please Log in to join the conversation.

More
5 years 9 months ago - 5 years 9 months ago #71238 by tpartner
tpartner replied the topic: Request for help: regular expression to test the FIRSTNAME token's value
You can use the following in the conditions designer:
^[aA]$

- When editing the question, open the conditions designer
- Click "Token fields"
- Click "First name"
- Click "Regular expression"
- Enter your expression


Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last Edit: 5 years 9 months ago by tpartner.

Please Log in to join the conversation.

More
5 years 9 months ago #71240 by guelphpeter
guelphpeter replied the topic: Request for help: regular expression to test the FIRSTNAME token's value
Thanks so very much for you help - really appreciated !

I'm still a bit stuck but very close I think - it's likely due to by newbie status for regular expressions.

Placing this reg expression in the condition works great if the FIRSTNAME token has only one character, and its value is "a".

^[aA]$

What I can't seem to figure out is what the regular expression should be to show the question if any character in the FIRSTNAME token contains the letter "a".

Thank you so much in advance if you can help me with this one.

Peter

Please Log in to join the conversation.

More
5 years 9 months ago #71241 by TMSWhite
TMSWhite replied the topic: Request for help: regular expression to test the FIRSTNAME token's value
Peter-

For LimeSurvey 1.91+, use this regular expression instead to test for any letter 'a' in the name:
[aA]

For 1.92, I had a typo. The relevance equation should be:
regexMatch('/[aA]/',TOKEN:FIRSTNAME)

/Tom

Please Log in to join the conversation.

More
5 years 9 months ago #71242 by guelphpeter
guelphpeter replied the topic: Request for help: regular expression to test the FIRSTNAME token's value
Thank you very much Tom and "tpartner" for all your help with this one.

It's working absolutely perfectly now !!!

Thanks so much and best wishes for a wonderful holiday season !

Peter

Please Log in to join the conversation.

More
5 years 9 months ago - 5 years 9 months ago #71271 by longchampshop
longchampshop replied the topic: Request for help: regular expression to test the FIRSTNAME token's value
I come to stuy,benefit a lot ,thanks all
Last Edit: 5 years 9 months ago by longchampshop.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now