4

I have kind of simple regexes that i am using.

It's so simple as:

"user/"
"user/[A-z0-9_-]"

These all work fine with ereg, but not preg.

How to convert it?

Thanks

Lars Hansen
  • 105
  • 1
  • 5

2 Answers2

7

It's most probably because your're missing the delimiters. Try this:

"~user/~"
"~user/[A-z0-9_-]~"
alexn
  • 57,867
  • 14
  • 111
  • 145
  • What is the point of delimiters? It seems like all the posix regexes works enclosed with those delimiters. To they add functionality or are they syntactic sugar? – Lars Hansen Mar 10 '11 at 18:29
  • 1
    Delimiters makes it possible to add modifiers. You can read more about it at http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php – alexn Mar 10 '11 at 18:52
0
ereg('jpg$', $query)

Turns into:

preg_match('@jpg$@', $query)
user4951
  • 32,206
  • 53
  • 172
  • 282