Jump to content

[SOLVED] Regex Help~


xenophobia

Recommended Posts

Alright, I want a searching regex statement to achieve this:

 

I want to search for an email address that is under the specified domain. Eg:

I want all the user under this domain: yahoo.

So:

[email protected] will return true.

[email protected] will return true.

[email protected] will return true.

... so on....

while

[email protected] will return false.

[email protected] will return false.

[email protected] will return false.

 

any idea? I am bad in REGEX. I need you guy's help.

Link to comment
https://forums.phpfreaks.com/topic/106393-solved-regex-help~/
Share on other sites

<pre>
<?php
$data = <<<DATA
Alright, I want a searching regex statement to achieve this:

I want to search for an email address that is under the specified domain. Eg:
I want all the user under this domain: yahoo.
So:
[email protected] will return true.
[email protected] will return true.
[email protected] will return true.
... so on....
while
[email protected] will return false.
[email protected] will return false.
[email protected] will return false.

any idea? I am bad in REGEX. I need you guy's help.
DATA;

preg_match_all('/\S+@yahoo\.com/', $data, $matches);
print_r($matches);
?>
</pre>

Link to comment
https://forums.phpfreaks.com/topic/106393-solved-regex-help~/#findComment-545709
Share on other sites

preg_match_all('/\S+@yahoo\.com/', $data, $matches);

print_r($matches);

 

Alright, the regex work fine.

 

Now i got a small request. How if i want to match more than just yahoo? Example like i want hotmail to be return true also. meaning:

[email protected] -> return true

[email protected] -> return true also

 

maybe i will have more than one email domain. How can I do that?

Link to comment
https://forums.phpfreaks.com/topic/106393-solved-regex-help~/#findComment-547838
Share on other sites

Alright. After figuring, I got this:

 

/^\S+@(?:yahoo|hotmail)\.\S*$/Uis

 

whereby if user enter any domain with yahoo or hotmail, it will return true. Now what I want is, I want to negate it! Meaning, if user using yahoo or hotmail, i want it to return false. How to do it!?

 

Please help!!!

 

Thank in advanced.

Link to comment
https://forums.phpfreaks.com/topic/106393-solved-regex-help~/#findComment-547948
Share on other sites

That work fine if user entered: [email protected] or [email protected]

 

But if user enetered: [email protected], it return false too! Meaning, it match! Suppose it is not.

 

Is it putting something like \b in between the `group`? But I tried, failed...

 

Please guide! Thanks a lot effigy~

Link to comment
https://forums.phpfreaks.com/topic/106393-solved-regex-help~/#findComment-549984
Share on other sites

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.