Stack Exchange
Stack Overflow
Questions
Tags
Users
About
Stack Overflow
Public
Questions
Tags
Users
About
What's wrong with the [ ] pattern in php?
Asked
Feb 23 '18 at 21:06
Active
Feb 23 '18 at 21:06
Viewed
48 times
1
Why does this pattern:
[A-z]+
Matches this successfully?
[][][][
php
regex
asked Feb 23 '18 at 21:06
user8661184
43
1
6
Use `[A-Za-z]`. It matches according to the ASCII table
–
ctwheels
Feb 23 '18 at 21:07
1
Because in ASCII the `[]` characters are between the lower and upper case letters.
–
Eugene Sh.
Feb 23 '18 at 21:08
You probably want `[A-Za-z]`, or use the `/i` option.
–
Alex Howansky
Feb 23 '18 at 21:09
As others said, the brackets are between 'A' and 'z' in the ASCII table. Snippet: `for ($i = ord('A'); $i <= ord('z'); $i++) { echo chr($i); }` => `ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz`
–
Steven Spasbo
Feb 23 '18 at 23:12
0 Answers
0