Skip to content

Instantly share code, notes, and snippets.

@matsuoshi
Created September 27, 2022 10:49
Show Gist options
  • Select an option

  • Save matsuoshi/e06ed942d84d0c16fe48fa691f2f8838 to your computer and use it in GitHub Desktop.

Select an option

Save matsuoshi/e06ed942d84d0c16fe48fa691f2f8838 to your computer and use it in GitHub Desktop.
正規表現の uフラグ
<?php
$subjects = [
'zenkaku',
'hankaku',
'あいうえお'
];
foreach ($subjects as $subject) {
preg_match('/^[a-z]+$/', $subject, $match);
var_dump($match);
}
echo '--------', PHP_EOL;
foreach ($subjects as $subject) {
// `/u` をつける
preg_match('/^[a-z]+$/u', $subject, $match);
var_dump($match);
}
@matsuoshi
Copy link
Author

% php regex.php                                                                                                  (:|✔ )
array(1) {
  [0]=>
  string(21) "zenkaku"
}
array(0) {
}
array(1) {
  [0]=>
  string(15) "あいうえお"
}
--------
array(1) {
  [0]=>
  string(21) "zenkaku"
}
array(0) {
}
array(0) {
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment