Hello everyone i want to preg_match [200932] this from a string. I tryied some pattern but didnt help, any idea?
+3
A:
Your question is very vague but I think you probably forgot to escape the square brackets. They denote a character class in RegEx.
preg_match('/\[200932\]/', $str, $matches);
If you were to use /[200932]/
it would mean "2 or 0 or 9 or 3".
Edit:
To capture numbers between square brackets:
/\[(\d+)\]/
That's
\[ A square bracket
( Start capturing group
\d+ A digit, 1 or more times
) End capturing group
\] A closing square bracket
Greg
2009-10-05 10:38:45
hy thanks i want [*] the numbers in the []
streetparade
2009-10-05 10:41:15
yours also doesnt work it returns array(1) { [0]=> array(1) { [0]=> string(1) "]" }
streetparade
2009-10-05 10:46:52
Thanks it worked array(2) { [0]=> array(1) { [0]=> string(8) "[200932]" }
streetparade
2009-10-05 10:48:34
this worked forme thank you:array(2) { [0]=> array(1) { [0]=> string(8) "[200932]" }
streetparade
2009-10-05 10:58:09
A:
Hello, not sure if I understand your question right, but here is it anyway:
[\[\]0-9]{8}
iamruss
2009-10-05 10:40:28
no it doesnt work. Is that difficult to understand i want the numbers between the square brackets
streetparade
2009-10-05 10:45:23
A:
You tried: #[([.])]#
Try this: \[([0-9]*)\]
(Without the * the string matches only one digit and you used . which matches on all chars even a,b,c,- or /)
Patrick Cornelissen
2009-10-05 11:34:08