2
   

Regular Expressions (Regex) Construction Advice

 
 
View Profile Monger
 
Reply Sun 5 Feb, 2006 06:31 pm
Since posting this thread on the web development forum several months ago I've gotten very involved with regular expressions. If anyone needs some help understanding or constructing a regex, lemme know in this thread and I'll be happy to try to help as time permits.

For those who have no idea what I'm talking about, a regular expression is a special text string for describing a search pattern...basically wildcards on steroids. For example, here's a regex that will find most any valid email address:

\b[a-z\d._%-]+@(?:[a-z\d-]+\.)+[a-z]{2,6}\b

That will match "my.name@my-website.com", but not "fake!email@a.b" or other invalid email address.

I could use that e.g. to check if someone entered a real email address in a web page, or I could replace it with whatever I want, which may incorporate all or only parts of the match (e.g. I could turn it into an HTML link).

Or maybe I want to find valid email addresses that are from anywhere but able2know.com ...to do so I'd adjust the regex pattern like so:

\b[a-z\d._%-]+@(?!able2know\.com\b)(?:[a-z\d-]+\.)+[a-z]{2,6}\b

As a web application developer, I now rely on regexes constantly in my work, but they can be very useful for non-developers as well (e.g. Microsoft Word allows advanced search and replace with a sort of quasi-regex support, and a number of other text editors including EditPad, which offers a nearly full-featured free version, support regex).

Want to take a list of names in Word and convert them to "Lastname, Firstname" format, or find any number that doesn't start with 0, or extract all phone numbers from a document, etc., etc.? A regular expression can help...
 
View Profile rhymer
 
  1  
Reply Mon 6 Feb, 2006 05:44 am
You have made an excellent offer here Monger.
I have been successful with a few simple regex's but complicated ones like your example require considerable (probably unavailable) effort from infrequent users of the regex 'tool' like myself.

Good on ya !!!!!
0 Replies
 
View Profile Francis
 
  1  
Reply Mon 6 Feb, 2006 06:19 am
ok.
0 Replies
 
 

Related Topics

The "Death" of the Computer Mouse - Discussion by Phoenix32890
Blue screen of Death - Question by dagmaraka
How does one uninstall a program? - Question by Woollcott
how do you type pi? - Question by C99
Conficker worm - Discussion by msolga
SYSTRAY MISSING - Discussion by Misti26
Broad Jump Client Foundation - Discussion by Mustang
 
  1. able2know
  2. » Regular Expressions (Regex) Construction Advice
Copyright © 2009 Horizontal Verticals :: Page generated in 0.34 seconds on 11/28/2009 at 12:40:50 Top End