Regex to validate string for having three non white-space characters

前端 未结 2 1933
旧时难觅i
旧时难觅i 2021-01-26 17:45

I am using parsley js for validating input and I am using the data-parsley-pattern which allows me to pass in regular expression.

I am trying to validate the string to m

2条回答
  •  醉梦人生
    2021-01-26 18:31

    \S{3,}
    

    \S{3,} match any non-white space character [^\r\n\t\f ]

    Quantifier: {3,} Between 3 and unlimited times, as many times as possible, giving back as needed [greedy]

    e.g. abc or abc def

    https://regex101.com/r/gO6sT3/1


    That, as pointed out by Wiktor Stribiżew, only matches consecutive characters. If you mean "the input can have any number of whitespaces, anywhere, as long as there are at least three non-whitespace characters anywhere" then maybe:

    .*\S.*\S.*\S.*
    

    Anything or nothing, non-witespace, anything or nothing, non-whitespace, etc.

    e.g. a b c or ab c or abc

    https://regex101.com/r/wY0kL4/1

    Also see anything and everything at the site: http://www.regular-expressions.info/

提交回复
热议问题