fork(8) download
  1. function pattern_checker(v)
  2. return string.match(v, '^[%d%a_.]+$') ~= nil and -- check if the string only contains digits/letters/_, one or more
  3. string.sub(v, 0, 1) ~= '.' and -- check if the first char is not '.'
  4. string.sub(v, -1) ~= '.' and -- check if the last char is not '.'
  5. string.find(v, '%.%.') == nil -- check if there are 2 consecutive dots in the string
  6. end
  7.  
  8. -- good examples
  9. print(pattern_checker("hello.com"))
  10. print(pattern_checker("hello"))
  11. print(pattern_checker("hello.com.com.com"))
  12. -- bad examples
  13. print(pattern_checker("hello.com."))
  14. print(pattern_checker(".hello"))
  15. print(pattern_checker("hello..com.com.com"))
  16. print(pattern_checker("%hello.com.com.com"))
Success #stdin #stdout 0s 2836KB
stdin
Standard input is empty
stdout
true
true
true
false
false
false
false