Article View: dc.org.linux-users
Article #3786Regular expressions in C
From: Joseph S. D. Yao
Date: Wed, 09 Aug 1995 00:00
Date: Wed, 09 Aug 1995 00:00
48 lines
2776 bytes
2776 bytes
The other night, at the DC LUG meeting at NIH, somebody mentioned that C didn't have regular expressions. I almost spoke up immediately to disagree, but a half-memory tickled the back of my head, and I help my peace until I could check my references. You see, Unix C has had regular expressions - regcomp and regex - for quite a few iterations now. I remembered that there had been some discussions regarding whether the AT&T regex were adequate, and whether a different version of regular expressions should really be used. Apparently, because of these discussions, no regular-expression routines were included in the ANSI C library definition! However, there apparently IS a definition of regex - regcomp and regex - in the IEEE 1003.2 (POSIX interface). I find that Henry Spencer has written a package to that standard. Henry has been doing Unix almost as long as I have; perhaps longer. When he does things, he does them "right!" - at least, per his own particular philosophy, with which I find myself very often in agreement. In this particular case, he implemented the standard exactly as written, pointing out its flaws along the way. His code is based on Berkeley regex. It's incompatible with Unix V8 regexp. GNU, in typical GNU fashion, decided to solve all possible problems at once in their version. Their version, "rx", apparently offers the following different regular-expression syntaxes: EMACS awk POSIX awk grep egrep POSIX egrep sed POSIX basic POSIX minimal basic POSIX extended POSIX minimal extended Although I don't find any documentation on it anywhere on my installed system, this is apparently the version delivered with my Linux system (Slackware). Which is better? GNU probably can do things that Henry's wouldn't even dream of. However, you'd better find the documentation - and it's likely to be extensive, since there are a LOT of options. Henry's is probably a good bit smaller and does exactly what it's defined to do (even when the definition is incorrect). You decide. Bottom line? C _does_ have regular expressions, and has had for a long time. ANSI C doesn't include it in the definition, though; so I wouldn't be surprised if some PC compiler that's better at a touchy- feely interface than at real work didn't include it. -- Joe Yao jsdy@cais.com - Joseph S. D. Yao
Technical Details
Message-ID:
<40b40k$8na@news.cais.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11663c,e0113a429646ab73,start X-Google-Attributes: gid11663c,public From: jsdy@cais2.cais.com (Joseph S. D. Yao) Subject: Regular expressions in C Date: 1995/08/09 Message-ID: <40b40k$8na@news.cais.com> X-Deja-AN: 107864510 organization: Hadron, Inc. [Posting from Cap. Area Internet Svcs.] newsgroups: dc.org.linux-users