6
6

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 2012-12-26
<?php

$symbols = '[\s\x21-\x2f\x3a-\x40\x5b-\x60\x7b-\x7e]';

for ( $i = 0; $i < 128; $i ++ )
{
	$chr = chr($i);
	echo sprintf('%03d', $i), ' ', $chr, ' ', preg_match("/$symbols/", $chr) ,PHP_EOL;
}

実行結果

000  0
001  0
002  0
003  0
004  0
005  0
006  0
007  0
008 0
009 	 1
010 
 1
011 
     0
012 
     1
 13 
014  0
015  0
016  0
017  0
018  0
019  0
020  0
021  0
022  0
023  0
024  0
025  0
026  0
027 0
028  0
029  0
030  0
031  0
032   1
033 ! 1
034 " 1
035 # 1
036 $ 1
037 % 1
038 & 1
039 ' 1
040 ( 1
041 ) 1
042 * 1
043 + 1
044 , 1
045 - 1
046 . 1
047 / 1
048 0 0
049 1 0
050 2 0
051 3 0
052 4 0
053 5 0
054 6 0
055 7 0
056 8 0
057 9 0
058 : 1
059 ; 1
060 < 1
061 = 1
062 > 1
063 ? 1
064 @ 1
065 A 0
066 B 0
067 C 0
068 D 0
069 E 0
070 F 0
071 G 0
072 H 0
073 I 0
074 J 0
075 K 0
076 L 0
077 M 0
078 N 0
079 O 0
080 P 0
081 Q 0
082 R 0
083 S 0
084 T 0
085 U 0
086 V 0
087 W 0
088 X 0
089 Y 0
090 Z 0
091 [ 1
092 \ 1
093 ] 1
094 ^ 1
095 _ 1
096 ` 1
097 a 0
098 b 0
099 c 0
100 d 0
101 e 0
102 f 0
103 g 0
104 h 0
105 i 0
106 j 0
107 k 0
108 l 0
109 m 0
110 n 0
111 o 0
112 p 0
113 q 0
114 r 0
115 s 0
116 t 0
117 u 0
118 v 0
119 w 0
120 x 0
121 y 0
122 z 0
123 { 1
124 | 1
125 } 1
126 ~ 1
127  0
6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?