Ereg deprecated problem


anyone can help to convert this

ereg(“^\[?[0-9\.]+\]?$”, $val2)

using preg_match?

I am trying

preg_match(“/^\[?[0-9\.]+\]?$/”, $val2)

however it does not work in the same way

thank you

no it works I was wrong , however anyone can tell me difference between

preg_match(“/^\[?[0-9\.]+\]?$/”, $val2)


preg_match(“{^\[?[0-9\.]+\]?$}”, $val2)

which seem to work in the same way ?

Yup, those do the same thing.
You can choose any character you like for the start and end of the expression, as long you use the same character for both.
The thing is that the character you choose has to be escaped if you use it in the expression itself, which is why some characters are a poor choice (like / which I find needs to matched quite a lot).
My personal preference goes to ~ because that almost never occurs in an expression. Of course that is personal, other people might prefer other characters.

I didn’t know it , very useful thank you

The difference is only in the delimiters, for how they should/can be used see