IT Community - Software Programming, Web Development and Technical Support

what is regular expression?

This is a discussion on what is regular expression? within the PHP Programming forums, part of the Web Development category; in php or Java Script i dont like a word regular expression. How can i understand the regular expression eascilly. ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-21-2008, 04:46 AM
saravanan saravanan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 181
saravanan is on a distinguished road
Default what is regular expression?

in php or Java Script i dont like a word regular expression. How can i understand the regular expression eascilly. please give a example from scratch to massive.

Thanks in advance.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-21-2008, 05:28 AM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: what is regular expression?

Hi,

A regular expression is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids. You are probably familiar with wildcard notations such as *.txt to find all text files in a file manager. The regex equivalent is .*\.txt.

But you can do much more with regular expressions. In a text editor like EditPad Pro or a specialized text processing tool like PowerGREP, you could use the regular expression \b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b to search for an email address. Any email address, to be exact. A very similar regular expression can be used by a programmer to check if the user entered a properly formatted email address. In just one line of code, whether that code is written in Perl, PHP, Java, a .NET language or a multitude of other languages.

Since "regular expressions" is a mouthful, you will usually find the term abbreviated as "regex" or "regexp". I prefer "regex", since it can be easily pluralized as "regexes".
__________________
Regards,
Senraj.A
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-23-2008, 08:05 PM
saravanan saravanan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 181
saravanan is on a distinguished road
Default Re: what is regular expression?

Thank you so much
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-27-2008, 06:27 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: what is regular expression?

Hi,
Here the small example

PHP Code:
<?php
$str 
"Hello World";
// Returns true if "Hell" is found anywhere in $str
ereg("Hell"$str);       
?>
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-27-2008, 06:30 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: what is regular expression?

this example Returns true if client browser is Netscape 2, 3 or MSIE 3.

PHP Code:
<?php
eregi
("(ozilla.[23]|MSIE.3)"$HTTP_USER_AGENT);  
?>
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-28-2008, 05:35 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: what is regular expression?

This example check valid email or not using regular expression if valid returns true.

PHP Code:
<?php

define
("EMAIL_REG""^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})$");

$vEmail 'abc@xyz.com';

eregi(EMAIL_REG$vEmail);
?>
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-28-2008, 05:40 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: what is regular expression?

This example for checking US zipcode format valid or not if valid returns true.

PHP Code:
<?php
define
("US_ZIPCODE_REG""^[[:digit:]]{5}(-[[:digit:]]{4})?$");

$vZip '12345';
eregi(US_ZIPCODE_REG$vZip);
?>
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-28-2008, 06:02 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: what is regular expression?

This example for checking US phone number format valid or not if valid returns true otherwise false.

PHP Code:
<?
define
("US_PHONE_REG""[0-9]{3}-[0-9]{3}-[0-9]{4}$");

$vPhone '123-456-7890';
eregi(US_PHONE_REG$vPhone);
?>
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-28-2008, 06:12 AM
sureshbabu sureshbabu is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Location: India
Posts: 101
sureshbabu is on a distinguished road
Send a message via AIM to sureshbabu Send a message via MSN to sureshbabu Send a message via Yahoo to sureshbabu Send a message via Skype™ to sureshbabu
Default Re: what is regular expression?

what is regular expression for address format?
__________________
Thanks
Regards
Sureshbabu Harikrishnan
+91 9884320017
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use Regular expression in Java? S.Vinothkumar Java Programming 3 11-28-2007 08:45 PM
Regular expression tips & tricks prasath Database Support 8 09-24-2007 09:55 PM
Regular expression Sathish Kumar C# Programming 23 09-10-2007 06:00 AM
Can any one give regular expression for this string? raj PHP Programming 1 07-24-2007 11:42 PM
Regular expression vadivelanvaidyanathan Perl 0 07-15-2007 06:21 PM


All times are GMT -7. The time now is 10:31 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0