Welcome to the LimeSurvey Community Forum

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

Word count BUT with utf8

  • DenisChenu
  • DenisChenu's Avatar Topic Author
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
5 years 3 months ago - 5 years 3 months ago #185907 by DenisChenu
Word count BUT with utf8 was created by DenisChenu
With regexMatch expressioon manager function : we can control number of word.

Proposed regexp is manual.limesurvey.org/Using_regular_expressions#Word_count/^ [-\w]+(?:\W+[-\w]+){0,199}\W*$/ (this allow word and -)
Code:
is_empty(this.NAOK) or regexMatch('/^[-\w]+(?:\W+[-\w]+){5,5}\W*$/', trim(this.NAOK))
6 words needed

It work for non utf8,


but not for UF8 caracter : aaaéaa is 2 word.

I search for regexp to replace \W an\w, but i don't find the good way …

Did someone already find a solution ?

I want javascript control (more easy … the count in screenshot can be easily improved) , but i want PHP control too …

Thanks …

Test survey attached
PS : maybe a solution can be count ([\s|!|\.|\?|,]) : word are number of space +1

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
Last edit: 5 years 3 months ago by DenisChenu.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar Topic Author
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
5 years 3 months ago - 5 years 3 months ago #185909 by DenisChenu
Replied by DenisChenu on topic Word count BUT with utf8
OK, space seems better, far as perfect but better
Code:
regexMatch('/^[\s\!\?\.\,\;\:\(\)]*[^\s\!\?\.\,\;\:\(\)]+(?:[\s\!\?\.\,\;\:\(\)]+[^\s\!\?\.\,\;\:\(\)]+){2,2}[\s\!\?\.\,\;\:\(\)]*$/',
    str_replace("'"," ", str_replace('"',' ',this.NAOK))
)
(for 2 words)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
Last edit: 5 years 3 months ago by DenisChenu.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose