[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: text processing as *the* problem
Quoth Dan Sugalski:
> Still, the question remains--what besides plain regexes would be
> interesting to have when doing string processing? Dealing with tightly
> structured nested data structures (like XML or Lisp) is one, but I'm sure
> there are others.
One deficiency in the usual regex model is that sometimes you want to
run a nested search-and-replace. That is, search for certain strings,
then perform a s/// (or several in sequence!) on only those substrings.
Sure, you can do this in most languages, but it takes a bit of clever
coding to get the replacement to occur on the original string. When I
had to do this a few years ago I ended up writing a C++ wrapper around,
I believe, the rx package, but it would've been nice to just whip up a
script (Perl or otherwise).
For an example of what I mean: say you wanted to convert social security
numbers (but not cardinal numbers like "10" or "5,000") into hyphen-
delimited lists of digits. What you want to do is something like
(find&replace "(\d)-?" "\1-")
(find&replace "-$" ""))
The trouble with being punctual is that nobody's there to appreciate it.
-- Franklin P. Jones