Generating regexes and Gmail filters
- 16 March, 2009 08:39
- Comments
Before I launch into my main thrust (a word that must be pronounced with a rolling "r") I have to direct you to a work of near genius, txt2re, an online regular expression code generator.
If you aren't au fait with regular expressions (also called regexes or regexps), they are formal descriptions of searches to be conducted on sequences of characters (or "strings") by a regular expression processor, that is, a program designed to process "regexes" (see the Wikipedia entry on regular expressions).
Regex is useful for jobs such as mining server logs and searching data files and txt2re makes generating code in Perl, PHP, Python, Java, Javascript, ColdFusion, C, C++, Ruby, VB, VBScript, J#.net, C#.net, C++.net or VB.net that perform these searches incredibly easy.
To use txt2re you give the service an example string and it shows you the substrings it recognizes and lets you select which ones you want to include in the output.
I did, however, say "near genius" as txt2re seems to have a bug that means the service doesn't always identify all of the "findable" substrings correctly. I was using txt2re to generate JavaScript code based on the following example entry in an Apache server access log:
192.168.10.11 - bob [16/Mar/2009:13:14:15 -0800] "GET /gibbs.gif HTTP/1.0" 200 5648
Txt2re failed to offer to treat the last digits in the string that show the data length as an integer -- it only offered them as four individual digits (see here), which would be useless if the data length was five digits long.
The solution was, oddly enough, to change the IP address in the example string to 1.1.1.1 and voila! I got the code I needed (see here). Despite this bug, the concept is way cool and a little creative tweaking of either your example or the generated code will get you the code for exactly the regex search you need. (Here is a telephone number parser in JavaScript I created using txt2re).
- Bookmark this page
- Share this article
- Got more on this story? Email TechWorld
- Follow TechWorld on twitter
- txt2re: headache relief for programmers :: regular expression generator
- Regular expression - Wikipedia, the free encyclopedia
- txt2re: headache relief for programmers :: regular expression generator
- txt2re: headache relief for programmers :: regular expression generator
- txt2re: headache relief for programmers :: regular expression generator
- Gmail
- Improving Productivity in the Connected Enterprise Through Collaboration
- Avaya Deploys the Avaya Desktop Video Device with the Avaya Flare® Experience
- Softsource gain edge through HP Converged Infrastructure and 3PAR storage technology
- USABILITY AS AN ERP SELECTION CRITERIA
- HP ALM YouTube channel – Demonstration videos
-
Lenovo ordered to pay €1920 for making French laptop buyer pay for Windows too
-
Wikileaks suspect to face US court-martial
-
Wikileaks suspect to face US court-martial
-
Telstra reports issue with BigPond email accounts
-
Samsung Galaxy S II Android phone
-
Windows 7 for Dummies® Dvd+book Bundle
-
Teach Yourself Visually Windows 7
-
Computers for Seniors for Dummies, 2nd Edition
-
Excel 2007 All-In-One Desk Reference for Dummies
-
Office 2007 All-In-One Desk Reference for Dummies
-
Windows 7 for Seniors for Dummies®
-
Windows 7 for Dummies®
-
Office 2007 for Dummies
-
Microsoft Office











Comments
Post new comment