fork download
  1. <?php
  2. $words = ['штаны', 'ёлка', 'слово'];
  3. $regexps = ['~^[а-я]+$~u', '~^[а-яё]+$~u'];
  4.  
  5. foreach($words as $word)
  6. foreach($regexps as $regexp)
  7. "Regexp: '%s', word: '%s', match: %s\n",
  8. $regexp,
  9. $word,
  10. preg_match($regexp, $word) ? 'true' : 'false'
  11. );
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Regexp: '~^[а-я]+$~u', word: 'штаны', match: true
Regexp: '~^[а-яё]+$~u', word: 'штаны', match: true
Regexp: '~^[а-я]+$~u', word: 'ёлка', match: false
Regexp: '~^[а-яё]+$~u', word: 'ёлка', match: true
Regexp: '~^[а-я]+$~u', word: 'слово', match: true
Regexp: '~^[а-яё]+$~u', word: 'слово', match: true