-1

I have this code to find email addresses in given text:

preg_match_all("|[a-zA-Z0-9-_.]+@[a-zA-Z0-9-]+.[a-zA-Z]+|",
"</b>a@bexample </b> a@bexample.co ",$out, PREG_PATTERN_ORDER);

And the output is like this:

   Array
       (
       [0] => Array
           (
                [0] => a@bexample//error one
                [1] => a@bexample.co
           )

   )

the first answer isn't true. why?

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
MAli Fahimi
  • 195
  • 11

1 Answers1

0

I forgot the "\" before "." it should be like this

"|[a-zA-Z0-9-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z]+|"
MAli Fahimi
  • 195
  • 11
  • 2
    You are missing addresses in subdomains (many ccTLDs like .uk have mandatory second levels, and there are deep hierarchies like k12.us). You are ignoring email addresses containing plus, apostrophe, percent sign, and a number of other permitted characters (mine contains a plus, and many services, including Gmail, allow a plussed suffix to your main address as a useful feature). See the linked question in @Ilya's comment for lots more to think about. – tripleee Aug 14 '14 at 06:47