Question

I want to preg_match [200932] this from a string.
I tryied some pattern but didnt help, any idea?

Was it helpful?

Solution

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

OTHER TIPS

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

[\[\]0-9]{8}

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 /)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top