0

please can someone help me with convert this string from eregi() to preg_match or preg_replace? Thank you very much!

$eregicheck = "^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}\$";
saby
  • 351
  • 1
  • 2
  • 18

1 Answers1

2

Sure:

$pregcheck = "(".$eregicheck.")i";

Done.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • 2
    @jeroen Matching brackets (of any type - parens, brace, square...) can be used as delimiters, with the added advantage of not needing any escaping (since they come in pairs). Parentheses are my personal preference because they remind me that the entire match is the first element of the match array. – Niet the Dark Absol Jun 17 '13 at 17:27
  • Wow, didn't know that, that's going to be useful... – jeroen Jun 17 '13 at 17:28
  • +1 for the delimiters, the i modifier isn't needed – Casimir et Hippolyte Jun 17 '13 at 17:30
  • 1
    @CasimiretHippolyte In the general case, `eregi` to `preg` requires the `i` modifier. In this particular case, though, you're right, because of the `a-z` and `A-Z` both being present. – Niet the Dark Absol Jun 17 '13 at 17:31