Jump to content

[SOLVED] Allow parenthesis...


Maq

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. [email protected]  and ([email protected]).

 

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. [email protected]  and ([email protected]).";
preg_match_all('/\b[^@\s]+@\S+?\.[a-z]+\b/i', $data, $matches);
print_r($matches)
?> 
</pre>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.