Need help with Preg_Match

Joined
Nov 8, 2017
Messages
35
Reaction score
11
I use this to get emails off of a web page, but some school emails have a / . I don't understand preg_match well enough to add a / to acceptable charters. Even after looking at examples online I had trouble with it.

Code:
$var = preg_match_all(
"/[a-z0-9]+[_a-z0-9.-]*[a-z0-9]+@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})/i",$body,$matches);

Thanks for your help,

Rick
 
Glad it's resolved. For future troubleshooting with REGEXs, check out this site:
regex101.com

It shows/explains what your regex is doing in real time, which is great for testing/writing code like preg_replace in PHP.
 
Glad it's resolved. For future troubleshooting with REGEXs, check out this site:
regex101.com

It shows/explains what your regex is doing in real time, which is great for testing/writing code like preg_replace in PHP.

That's great!

for some reason my errors don't show on iPage so I've been doing the echo thing.

Mahalo,
Rick
 
While you're busy editing your preg_match, change this part [a-z]{2,4})/i to something like [a-z]{2,20})/i
That's the domain capturing part, and since there are TLD's with more than 4 characters you could miss for example emails from .online or .academy domains.
 
Maybe I can give back a little. I use Google Drive a lot and found phpedity to be useful. It will even place a little red mark near any errors. The error notifier is a little convoluted when you forget a ; or a } but at least you know there's an error.

Rick
 
Back
Top