LoginSignup
0
0

More than 1 year has passed since last update.

PHP 正規表現を用いて文字列のマッチを判定する

Posted at

目的

  • PHPにて正規表現を用いた文字列評価の方法をまとめる

情報

方法

  • preg_match()メソッドを使用する。
  • 下記のように記載する。
    • preg_match('正規表現', '評価する文字列')
  • 正規表現にマッチしていた場合は1が、マッチしていなかった場合0が返される。
  • 具体例

    • 下記を実行した時は1が返される。

      <?php
      
      echo preg_match('/(https?:\/\/[^\s]*)/', 'https://qiita.com/miriwo');
      
    • 下記を実行した時は0が返される。

      <?php
      
      echo preg_match('/(https?:\/\/[^\s]*)/', 'test');
      

      参考文献

  • https://www.php.net/manual/ja/function.preg-match.php

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0