473,554 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regular expression

Hi,

being not very good at php regular expression, could anyone help me giving
the regular expression for :
- an e-mail address,
- a website address (including sub-domain if possible).

many thanks in advance,
--
nyso
Jul 17 '05 #1
8 4919
nyso wrote:
being not very good at php regular expression, could anyone help me giving
the regular expression for :
- an e-mail address,
- a website address (including sub-domain if possible).


These are primitive, but have worked for me:
// replace URLs that aren't in an anchor tag
$pattern='/(http:\/\/[^\s\"\)<>]+)/i';

// get email addresses to link
$pattern='/([a-z][a-z0-9_.-\/]*@[^\s\"\)\?<>]+)/i';

These are patterns that are used with the preg_* functions

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #2
While thinking about how cool George Washington was, nyso blurted:

being not very good at php regular expression, could anyone help me giving
the regular expression for :
- an e-mail address,


here's a cool function for checking if an email address is valid:
(please pardon the ridiculous linewrapping)

function is_email($email ) {

return(preg_mat ch("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aer o|af|ag|ai|al|a m|an|ao|aq|ar|a rpa|as|at|au|aw |az|ba|bb|bd|be |bf|bg|bh|bi|bi z|bj|bm|bn|bo|b r|bs|bt|bv|bw|b y|bz|ca|cc|cd|c f|cg|ch|ci|ck|c l|cm|cn|co|com| coop|cr|cs|cu|c v|cx|cy|cz|de|d j|dk|dm|do|dz|e c|edu|ee|eg|eh| er|es|et|eu|fi| fj|fk|fm|fo|fr| ga|gb|gd|ge|gf| gh|gi|gl|gm|gn| gov|gp|gq|gr|gs |gt|gu|gw|gy|hk |hm|hn|hr|ht|hu |id|ie|il|in|in fo|int|io|iq|ir |is|it|jm|jo|jp |ke|kg|kh|ki|km |kn|kp|kr|kw|ky |kz|la|lb|lc|li |
lk|lr|ls|lt|lu| lv|ly|ma|mc|md| mg|mh|mil|mk|ml |mm|mn|mo|mp|mq |mr|ms|mt|mu|mu seum|mv|mw|mx|m y|mz|na|name|nc |ne|net|nf|ng|n i|nl|no|np|nr|n t|nu|nz|om|org| pa|pe|pf|pg|ph| pk|pl|pm|pn|pr| pro|ps|pt|pw|py |qa|re|ro|ru|rw |sa|sb|sc|sd|se |sg|sh|si|sj|sk |sl|sm|sn|so|sr |st|su|sv|sy|sz |tc|td|tf|tg|th |tj|tk|tm|tn|to |tp|tr|tt|tv|tw |tz|ua|ug|uk|um |us|uy|uz|va|vc |ve|vg|vi|vn|vu |wf|ws|ye|yt|yu |za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $
email));

}

/joe
--
A switch is ~bastardized!
Jul 17 '05 #3
nyso wrote:
being not very good at php regular expression, could anyone help me giving
the regular expression for :
- an e-mail address,


Why? It'd be unthinkably messy.

--
Jock
Jul 17 '05 #4
> > being not very good at php regular expression, could anyone help me
giving
the regular expression for :
- an e-mail address,


Why? It'd be unthinkably messy.

--
Jock


No, it seems easy to regex users.
E-mail is ok but url seems more difficult.
--
nyso
Jul 17 '05 #5
"Justin Koivisto" <sp**@koivi.com > a écrit dans le message de news:
Jy************* ***@news7.onvoy .net...
nyso wrote:
being not very good at php regular expression, could anyone help me giving the regular expression for :
- an e-mail address,
- a website address (including sub-domain if possible).


These are primitive, but have worked for me:
// replace URLs that aren't in an anchor tag
$pattern='/(http:\/\/[^\s\"\)<>]+)/i';


for the url regex, I tested it and it matches a simple "test" string as the
minimum should be "test.somthing" .
any idea ?
--
nyso
Jul 17 '05 #6
nyso wrote:
No, it seems easy to regex users.

---------^^^^^

--
Jock
Jul 17 '05 #7
"nyso" <ny**@no-spam.org> wrote in message news:<3f******* *************** *@news.free.fr> ...
being not very good at php regular expression, could anyone help me giving the regular expression for :
- an e-mail address,


Why? It'd be unthinkably messy.

--
Jock


No, it seems easy to regex users.
E-mail is ok but url seems more difficult.


It is easy for you too. Just try http://weitz.de/regex-coach

---
"Learn from yesterday, live for today, hope for tomorrow. The
important thing is to not stop questioning."---Albert Einstein
Email: rrjanbiah-at-Y!com
Jul 17 '05 #8
> > No, it seems easy to regex users.
E-mail is ok but url seems more difficult.


It is easy for you too. Just try http://weitz.de/regex-coach

---
"Learn from yesterday, live for today, hope for tomorrow. The
important thing is to not stop questioning."---Albert Einstein
Email: rrjanbiah-at-Y!com


thanks for the link !

--
nyso
Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4156
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) ...
4
5123
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following testMyColumn{1, 100}Test Basically I want the regular expression to add the word test infront of the
4
3212
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go over each document, find out if it contains a header and/or a footer and extract only the main content part. The headers and the footers have no...
11
5357
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However, I want to use the text included within the brackets to do a lookup so that I can replace the expression with the new text. For example:
3
3202
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is that this will one or more occurrences to replace all the white space between with a comma. This search ElseIf InStr(1, indivline, "$") Then insert...
7
3802
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way...
9
3346
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use an app call The Regulator, which makes it pretty easy to build and test regular expressions. As a warning, I'm real weak with regular...
25
5137
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access...
1
4364
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find the first regular expression that matches the string. I've gor the regular expressions ordered so that the highest priority is first (if two or more...
1
3383
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "": --------------------------------- myStringVar = myStringVar.replace("^" + iName + "=,($|&)", ""); --------------------------------- The following DOES replace it though:...
0
7578
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5414
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3530
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1111
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.