1. Computing

Readers Respond: Real World Examples Needed: Why/When do You Use RegEx in Your Delphi Code?

Responses: 12


String handling is one of the most common operations in any program. Delphi provides dozens of string related routines. Some of them you are, surely, using in all your applications - Pos, IsDelimiter, MatchesMask...

A common task for these procedures is to provide some kind of string comparison according to certain specific rule.

If you need to recognize patterns in text where patterns (rules) are much more complex, you would turn to using regular expressions.

What's your story? Have you ever used RegEx in Delphi? Why? What for? Let us learn something new from your experience - give us some real world examples.

I need it all the time! Ascii editors

I use regular expressions in all my applications which use all the time regular expression. You cannot have an Ascii editor without having the use of regular expressions.

To Find Links

Supporting law enforcement, we parse in-house reports we generate for patterns. We then look to see if there are any commonalities between cases.

Sysadmin configuration

regex is mostly something done by webprogrammers, but also by sysadmins. We mostly add the ability for configurable matches to enter regex in our sysadmin tools, since knowledge is common under sysadmins. Not always easy btw, since you have to make sure that it can't be done on too large dataasets, and regex are not powerful enough for some matching forms (e.g. it can't validate a mathematical expression)
—Guest Toolvendor

Fraud Analysis

I use regex to look for fraudulent vendors and determine patterns in transactions.
—Guest xyzeugene

Gad D Lord

For parsing, validation of file formats. For database integrity validation of manually matherialized columns. For almopst anything. I use a unit coming from the DevExpress VCL package.
—Guest Gad D Lord

Parsing and input validation

A combination of a state machine and some regex recognizers will permit the parsing of a (semi)structured text without having to resort to a full blown tplex/tpyacc work-of-art. Systools (nee) turbopower provides a regex validator that connects with an edit control. How slick! It's so much better to manage data at input than try to correct foul-ups after the incorrect data's been stored.

I use RegExp for better user experience

Example 1: I made an editbox that accept a capacitor value written as "1n2 F", "1.2 nF" or "1200pF" etc. the value actually stored is harmonized to 1.2nF for consistent text search. Example 2: The user does not have to specify the actual format of a text file (i.e. Bill of Material), the RegExp pick the correct data and the user does not have to convert his file to make the file useful for the program.
—Guest RichardThulstrup

Reg-ex essential

We use them to parse english-language legislation and regulation databases, user-input for searching a chemical names database and to isolate data points from streams.
—Guest Karl

Analyzing medical progress notes

I have developed a clinical decision support application for primary care doctors. It works in the background to alert the physician about potential problems (non-compliance to guidelines) for individual patients. The application analyzes various sorts of data from medical records, including free-text format progress notes. Regular expressions are used to extract smoking status, patient weight, height, diagnoses, lab results and drug prescription information. RegExes are invaluable in this context, and I would like to thank Jan Goyvaerts for his TPerlRegEx components for Delphi.
—Guest Magne Rekdal

Use them a good bit

We develop a log analyzer tool (Proxy/ISA Log Analyzer) that has the need to pull out and report on individual components of URL's. We use TRegExpr.
—Guest Lucas Pitts

Used RegExp in VB2Delphi

I used regexps in my VB2Delphi conversion tool to parse some parts of a VB project file, specifically to split the parts of the OBJECT and REFERENCE settings. On the other hand, the VBP parsing code was the only part where I used standard Delphi string handling functions. In the lexer, for example, I did stuff with CHAR buffers, hash tables, etc.
—Guest Albert Almeida

We use them very much

We develop a web filtering program (www.kidscontrol.eu) and use it heavily for pattern matching in URLs and web page text, as well as for findinmg overlapping rules in our filter rules database.

©2014 About.com. All rights reserved.