Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.
May 4, 2007
ColdFusion has supported Regular Expressions for a while, but I've always missed a REMatch() function, one that would locate all matches and return them. Over the years several of us have written our own functions to do this, but that's no longer needed - REMatch() and REMatchNoCase() are both in Scorpio.
August 25, 2005
I now have books available in Russian! Sams Teach Yourself SQL in 10 Minutes (3rd edition) and Sams Teach Yourself Regular Expressions in 10 Minutes have both just been released in Russian by Williams Publishing. Links to the new Russian editions are on the book pages. The full list of non-English editions of my books (15 different languages to date) has also been updated.
May 5, 2004
TechBookReport has reviewed my "Sams Teach Yourself Regular Expressions In 10 Minutes", giving it a verdict of "A pretty good introduction", and concluding that "the book provides a painless way into regular expressions. It takes a simple approach and keeps focused on showing how to get the job done. If you're already a regex regular then the chances are that there's not much new here for you, but if you're just starting out then this is a pretty good place to start." The full review is at http://www.techbookreport.com/tbr0079.html, and the book page is http://www.forta.com/books/0672325667/. Thanks to Pan Pantziarka for bringing this to my attention.
May 4, 2004
This is quite the compliment. UK IT Magazine, The Register, has proclaimed that my "Sams Teach Yourself SQL in 10 Minutes has established itself as the gold standard for introductory SQL books", and is recommending both that book and my new "Sams Teach Yourself Regular Expressions in 10 Minutes". Story at http://www.theregister.co.uk/2004/05/04/10_minutes_for_a_new_skill/. Thanks to Dan Alig for bringing this to my attention. (FYI, links to both books are at http://www.forta.com/books/).
April 4, 2004
U.K. IT online magazine, The Register, briefly reviewed (and discounted) my new "Sams Teach Yourself Regular Expressions in 10 Minutes" at http://www.theregister.co.uk/content/31/36664.html (book info at http://www.forta.com/books/0672325667/). Thanks to Lucas Sherwood for letting me know about this one.
March 12, 2004
Several of you wrote to tell me that you tried to buy my new "Sams Teach Yourself Regular Expressions in 10 Minutes" (see http://www.forta.com/books/0672325667/) from Amazon.com, only to be told that it was backordered. Indeed, Amazon.com ran out of their entire stock within a day (which is why the status changed from "Usually ships within 24 hours" to "Usually ships within 2 to 3 days"). Thankfully, Amazon.com has replenished their stock already. I apologize for the inconvenience, and thank you for your continued support.
It had to happen, several readers have found typos in my new "Sams Teach Yourself Regular Expressions in 10 Minutes", and so the errata is now online (link at the bottom of http://www.forta.com/books/0672325667/.
March 10, 2004
Two days after is started shipping, my new "Sams Teach Yourself Regular Expressions in 10 Minutes" made it onto the Amazon.com Bestsellers list, debuting at #3 in the "Computers & Internet" category. (#1 is a title on Mac OSX, #2 is on Adobe Photoshop, #4 is on Windows Server 2003, quite a diverse list). List is at Books, Bestsellers, and then select the category from the list on the left. Cool! :-)
March 7, 2004
My latest book, "Sams Teach Yourself Regular Expressions in 10 Minutes", is now available and shipping. This new title is modeled on my best-selling "Sams Teach Yourself SQL in 10 Minutes", is targeted at the same audience, and follows the same format and pace of study. Checking in at a svelte 150 pages, this is a highly compact, and very readable title. "Sams Teach Yourself Regular Expressions in 10 Minutes" will teach you the regular expressions that you really need to know, starting with simple text matches and working up to more complex topics, including the use of backreferences, conditional evaluation, and look-ahead processing. You'll learn what you can use, and you'll learn it methodically, systematically, and simply by using clear and practical examples and solving real problems - all in lessons that will each take 10 minutes or less to complete. Includes coverage of Perl, ColdFusion, ASP, Java, .NET, JavaScript, and more. Details at http://www.forta.com/books/0672325667/. Enjoy!
November 28, 2003
Need to match zip codes or postal codes? Of course, no two countries use the same format. But here are solutions for USA, Canada, and the United Kingdom.
The USA format is simple, five digits as 99999 or zip+4 as 99999-9999. A simple RegEx could be: \d{5}(-\d{4})? If you want to omit zips with a trailing hyphen (as in 99999-) then you could use a lookahead condition: \d{5}(?(?=-)-\d{4})
Canada is a little trickier, the format looks like A1A 1A1 which can be easily matched with: [A-Z]\d[A-Z] \d[A-Z]\d
However, there is one rule that may be employed to improve validation, the opening character of the set of characters (technically called the "forward sortation area" or FSA) identifies the province, territory, or region (there are 18 characters that are valid in this position, A for Newfoundland and Labrador, B for Nova Scotia, K, L, N and P for Ontario excluding Toronto which uses M, and so on.), and so validation should ideally check to ensure that the first character is a valid one. And so, here is a better Canadian postal code regular expression: [ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d
Good old UK is the trickiest of the three. United Kingdom postcodes, as defined by the Royal Mail, are five, six, or seven characters and digits (that includes a single space). Postcodes are made up of two parts, the "outward postcode" (or outcode), and the "inward postcode" (or incode). The outcode is one or two alphabetical characters followed by one or two digits, or one or two characters followed by digit and a character. The incode is always a single digit followed by 2 characters (any characters excluding C, I, K, M, O, and V). The incode and outcode are separated by a space. Here's the regular expression: [A-Z]{1,2}\d[A-Z\d]? \d[ABD-HJLNP-UW-Z]{2}
If you have any other countries or formats to share, please do so.
November 25, 2003
Earlier today I needed URL input validation (my form prompted for a URL, I needed to validate that what was provided was a syntactically valid URL). URL validation is actually rather complicated, but the following regular expression worked for me: https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)? This one allows both http and https, supports an optional port, and allows paths and query strings too. Oh, it also works with both JavaScript (and can thus be used with ) and CFML.
September 5, 2003
I am a night person, the wee hours are when I get most inspired. Here's a regular expression I wrote last night, um, make that this morning. It matches an IP address, and also ensures that the values are within the allowed range (0-255). (((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))
|