1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

正規表現あれこれ(メモ)

Last updated at Posted at 2017-06-11

正規表現について

※ 随時更新

基本構文

囲みに使う文字

/正規表現/
|正規表現|
|正規表現|
# 正規表現#
%正規表現%

行の先頭

/^正規表現/

行の末尾

/正規表現$/
/正規表現\z/

パターン

/を正規表現でマッチさせたい

|正規表現\/|

半角英字

/^[a-zA-Z]+$/

半角英数字

/^[a-zA-Z0-9]+$/

年月フォーマット(yyyy/mm)にマッチさせたい

|^(\d{4})\/(\d{2}\z)|  

():グループ化。()の中に記載された内容が1回以上繰り返しがある
\d:半角数字の0~9
{}:{}の前のものが4個続く

その他

  • preg_matchでマッチしない条件
function notMatch(){
  if(!preg_match("/正規表現/")) {
    echo "マッチしない場合に処理される";
  } 
}
1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?