1
   

Regular Expressions (Regex) Construction Advice

 
 
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 "[email protected]", but not "[email protected]" 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...
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 1 • Views: 1,124 • Replies: 2
No top replies

 
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
 
Francis
 
  1  
Reply Mon 6 Feb, 2006 06:19 am
ok.
0 Replies
 
 

Related Topics

Clone of Micosoft Office - Question by Advocate
Do You Turn Off Your Computer at Night? - Discussion by Phoenix32890
The "Death" of the Computer Mouse - Discussion by Phoenix32890
Windows 10... - Discussion by Region Philbis
Surface Pro 3: What do you think? - Question by neologist
Windows 8 tips thread - Discussion by Wilso
GOOGLE CHROME - Question by Setanta
.Net and Firefox... - Discussion by gungasnake
Hacking a computer and remote access - Discussion by trying2learn
 
  1. Forums
  2. » Regular Expressions (Regex) Construction Advice
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 04/25/2024 at 07:50:13