views:

154

answers:

3

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
hy thanks i want [*] the numbers in the []
streetparade
yours also doesnt work it returns array(1) { [0]=> array(1) { [0]=> string(1) "]" }
streetparade
Thanks it worked array(2) { [0]=> array(1) { [0]=> string(8) "[200932]" }
streetparade
this worked forme thank you:array(2) { [0]=> array(1) { [0]=> string(8) "[200932]" }
streetparade
A: 

Hello, not sure if I understand your question right, but here is it anyway:

[\[\]0-9]{8}
iamruss
no it doesnt work. Is that difficult to understand i want the numbers between the square brackets
streetparade
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