Jump to content

Recommended Posts

I have a regular expression

"/({0,1}^(*[A-Za-z0-9_-]+@[A-Za-z0-9_-]+\.([A-Za-z0-9_-][A-Za-z0-9_]+)$){0,1}/"

 

I want to be able to recognize and email address by itself or have parenthesis around it.  I tried adding (* in the beginning and )* at the end but PHP doesn't like it.  I'm not very good with regex, and help is appreciated.  Thanks.

Link to comment
https://forums.phpfreaks.com/topic/121296-solved-allow-parenthesis/
Share on other sites

I'm using preg_match_all.  Sorry, I'm just not familiar with regex because I usually just google what I need.  But overall I just need to find a regex to locate emails with and without parenthesis around it.  e.g. tim@yahoo.com  and (tim@yahoo.com).

 

Thanks,

Tim

How about something generic like this?

 

<pre>
<?php
$data = "I'm using preg_match_all.  Sorry, I'm just not familiar with regex because I usually just google what I need.  But overall I just need to find a regex to locate emails with and without parenthesis around it.  e.g. tim@yahoo.com  and (tim@yahoo.com).";
preg_match_all('/\b[^@\s]+@\S+?\.[a-z]+\b/i', $data, $matches);
print_r($matches)
?> 
</pre>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.