Using Regular Expressions in PHP

Some email addresses have a + sign in their username. I cannot seem to get the script to work if I ad the plus sign in that area?
IE eregi(‘[1]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$’, $email)


  1. a-zA-Z0-9._-+ ↩︎

Hyphen (-) has a special meaning if not at the beginning or end of a character class so you shouldn’t add the plus after the hyphen. You should add it anywhere else to keep the hyphen at the end:


eregi('^[a-zA-Z0-9._+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z.]{2,5}$', $email)


  1. a-zA-Z0-9._-+ ↩︎

it improve the knowledge of the students.

Your tutorial doesn’t cover domains such as co.uk where you have both a TLD and a 2LD. Or gTLD such as museum or travel.

The eregi function is history. PHP6 delete this, onli will work the perl reg exp…

Bye!

This script is extremely outdated.

Nice article. But I have a problem. How do I match a sentence under a quotation? For example, if the text is

I need you help to ‘get sentence under it’. Pleas help me.

Look at above text. I need to match the sentence which is under the single quotation. Please help me by providing appropriate regular expression.

hkabir, this article is very old (although you may not realise it) and it would be better if you asked in the PHP forum.

Yet, I will simply tell you that if those single quotation are part of the text you need to look for, you simply escape them with a backslash.

As an example, you have this sentence

$string="This is a very 'simple sentence' with a bit of text."

and you want to look for the string 'simple sentece’ with which includes those single quotes.

eregi('\\'simple sentence\\' with', $string)

Eregi is a function that now is deprecated fo, there is an extension called PRCE based on perl and regular expressions, of course