0

Possible Duplicate:
Converting ereg expressions to preg

I have used this regex in php < v5.3.0

ereg('^http://www.w3.org/[0-9]{4}/XMLSchema$',$value)

As I updated to php v.5.3.0 I am trying to use preg_match(), but I have hard time creating PCRE regex which is equivalent:

preg_match('/^http\\:\\/\\/www\\.w3\\.org\\/[0-9]{4}\\/XMLSchema$/',$value)

Could someone help on this one?

Community
  • 1
  • 1
azec-pdx
  • 4,790
  • 6
  • 56
  • 87
  • 3
    Try `preg_match('#^http://www\.w3\.org/[0-9]{4}/XMLSchema$#', $value)`. You can use other non-alphanumerics as the regexp delimiter, not just `/`, and that usually results in more readable expressions. – DCoder Jul 23 '12 at 10:18
  • Hi, thanks for quickness - actually this worked: preg_match('/^http://www\.w3\.org/[0-9]{4}/XMLSchema$/', $value). Does it matter if it starts with # or /? – azec-pdx Jul 23 '12 at 10:39
  • 1
    @ZeC: No, it doesn't matter; you can use any symbol – Igor Chubin Jul 23 '12 at 11:01

1 Answers1

2

You can you the same expression as in ereg:

preg_match('@^http://www[.]w3[.]org/[0-9]{4}/XMLSchema$@',$value)

Just take @ instead of / as a delimiter. And don't forget to escape dots (. means "any symbol" in a regular expression). You can do this using backslashes but I prefer symbol class [.] for that.

Igor Chubin
  • 61,765
  • 13
  • 122
  • 144