Welcome, Guest
Username: Password: Remember me

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

Request for help: regular expression to test the FIRSTNAME token's value 2 years 11 months ago #71222

  • guelphpeter
  • guelphpeter's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 36
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

Re: Request for help: regular expression to test the FIRSTNAME token's value 2 years 11 months ago #71226

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
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
The administrator has disabled public write access.

Re: Request for help: regular expression to test the FIRSTNAME token's value 2 years 11 months ago #71232

  • guelphpeter
  • guelphpeter's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 36
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

Re: Request for help: regular expression to test the FIRSTNAME token's value 2 years 11 months ago #71238

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4371
  • Thank you received: 829
  • Karma: 381
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

Untitled-1_2011-12-24.gif
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 2 years 11 months ago by tpartner.
The administrator has disabled public write access.

Re: Request for help: regular expression to test the FIRSTNAME token's value 2 years 11 months ago #71240

  • guelphpeter
  • guelphpeter's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 36
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

Re: Request for help: regular expression to test the FIRSTNAME token's value 2 years 11 months ago #71241

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
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
The administrator has disabled public write access.

Re: Request for help: regular expression to test the FIRSTNAME token's value 2 years 11 months ago #71242

  • guelphpeter
  • guelphpeter's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 36
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

Re: Request for help: regular expression to test the FIRSTNAME token's value 2 years 11 months ago #71271

I come to stuy,benefit a lot ,thanks all
Last Edit: 2 years 11 months ago by longchampshop.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.414 seconds
Donation Image