Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Extracting part of string from the answer for validation

  • arg0naut91
  • arg0naut91's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 7 months ago - 4 years 7 months ago #187245 by arg0naut91
I'd like to extract part of the string from the answer.

For instance, if "XXX - Y99" is the answer, I'd like to extract the second part ("Y99") and validate if it is equal to TOKEN:ATTRIBUTE_2.

Is something like that feasible?

Regular expression in itself is not a problem (in my case even something like '/Y.*/' would work), but I don't know how to extract it from the answer (e.g. from {q1.shown}).

Any ideas?

P.S. For some reason I cannot use Javascript so this is not an option.
Last edit: 4 years 7 months ago by arg0naut91.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 7 months ago #187246 by holch
So this seems to be a closed question, if you want to compare it to q1.shown, right? So you actually already know what is written in this specific answer, right?

XXX are placeholders or would this really be XXX and are all answers structured the same?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • arg0naut91
  • arg0naut91's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 7 months ago - 4 years 7 months ago #187248 by arg0naut91
Indeed, it is a multiple choice question with pre-defined answers like XXX - Y99, DDD - Y10, EEE - Y88,...

These are all placeholders of course, but the structure is similar.

However due to the fact that in TOKEN:ATTRIBUTE_n I only have strings like ("Y99", "Y10", "Y88"), I cannot do a direct comparison in the sense of {q1.shown} == TOKEN:ATTRIBUTE_n.
Last edit: 4 years 7 months ago by arg0naut91.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 7 months ago #187251 by DenisChenu

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: gabrieljenik
The topic has been locked.
  • arg0naut91
  • arg0naut91's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 7 months ago #187260 by arg0naut91
Unfortunately this wouldn't work as the Y* part can be of different length; e.g. it can also be 'Y1', etc.

I'd need to be able to extract it regardless of length - likely with regex.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 7 months ago - 4 years 7 months ago #187262 by tpartner
Maybe:

Code:
{substr(q1.shown, (strpos(q1.shown, ' - ')+3)) == TOKEN:ATTRIBUTE_n}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 7 months ago by tpartner.
The following user(s) said Thank You: DenisChenu, arg0naut91
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 7 months ago #187263 by Joffm
Then you have to do it in two steps.

First search search the index of "-" with function "strpos"
then you extract the part after "-" by "substr" and "trim".

E.g.
{trim(substr(q1.shown,strpos(q1.shown,"-")+1))}

{trim(substr("XXX - Y99",strpos("XXX - Y99","-")+1))} --> Y99
{trim(substr("XXX - Y9876",strpos("XXX - Y9876","-")+1))} --> Y9876
{trim(substr("XXX-V1",strpos("XXX-V1","-")+1))} --> Y1

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu, arg0naut91
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 7 months ago - 4 years 7 months ago #187264 by tpartner
Isn't that what I said? (except I am accounting for spaces in " - ")

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 7 months ago by tpartner.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 7 months ago #187265 by Joffm
@tpartner
So we sent it at the same time.
You sent while I was writing and trying.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • arg0naut91
  • arg0naut91's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 7 months ago - 4 years 7 months ago #187288 by arg0naut91
Thanks @tpartner and @Joffm - this works!
Last edit: 4 years 7 months ago by arg0naut91.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose