Welcome to the LimeSurvey Community Forum

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

Including apostrophe as part of a word for word count

  • joleitao
  • joleitao's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 6 months ago #189039 by joleitao
Hello,

I am sorry if this was already answered somewhere else, but I was extensively googling before and I could not find an answer to my question. I am also new to LimeSurvey and regular expressions so this question might be rather basic.

I want to have a word count that considers that apostrophes can be part of a word (e.g. isn't should count as one word and not two).
In some part of the manual Limesurvey suggests using regex101.com to test regular expressions. The regular expression

^\W*(?:[a-zA-Z0-9'-]+\b\W*){1,3}$


works exactly as expected if I test it in this website, but when I try to translate it to the validation fields (equation and tip) e.g. as such

regexMatch('/^\W*(?:[a-zA-Z0-9"'"-]+\b\W*){1,3}$/', Abstract.NAOK)


this format is not accepted.

Is there a way of translating the above regular expression into a format recognized by LimeSurvey?

Thanks in advance.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 6 months ago #189040 by tpartner
Try changing the wrapping quotes:

Code:
regexMatch("/^\W*(?:[a-zA-Z0-9'-]+\b\W*){1,3}$/", Abstract.NAOK)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • joleitao
  • joleitao's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 6 months ago #189044 by joleitao
Hi Tony,

thanks so much for your fast reply, that did the trick for the formatting part.

However, it still does not work in terms of the action it is supposed to perform.
If I put in the validation tip:

{if(regexMatch("/^\W*(?:[a-zA-Z0-9_'-]+\b\W*){0,3}$/", Abstract.NAOK), 'Please enter your abstract', 'Your abstract exceeds 3 words')}

it appears to be counting the ' as a separate word (regardless of whether it is presented in isolation or within a letter sequence, e.g. if I type "isn't" this already counts as 3 words and I get the 'Your abstract exceeds 3 words' message if I type any other word character).
Yet, I tried different string variations using the same expression in the regex101.com website and it worked (e.g. I can write "isn't this annoying" without problems).
The weird part is that this appears to be specific for the ' , if I do the same with the -, which does also not necessarily belong to a word character (right?), it works fine.

Can you think of where this discrepancy might be coming from?

Thanks again.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 6 months ago #189046 by tpartner
I'm sorry, I don't have an explanation and am not in a position to test this week.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • joleitao
  • joleitao's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 6 months ago #189048 by joleitao
Ok, thank you anyway.
And thanks as well for solving many of the other problems I encountered indirectly - your answers to other people have been really useful!
Have a nice day!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose