Can we do regular expression processing in C ?

  • Thread starter Mahendra Kutare
  • Start date
M

Mahendra Kutare

Or do we need to have any specific library ?

I am more interested in knowing if we can do string pattern matching
regular expression processing with C.

Thanks
Mahendra
 
I

Ian Collins

Mahendra said:
Or do we need to have any specific library ?

I am more interested in knowing if we can do string pattern matching
regular expression processing with C.
Not in standard C, there are plenty of extensions (POSIX regex for example).
 
I

Ian Collins

Don said:
Not being required by the standard doesn't make them any less "standard C".
OK, to disambiguate my reply further, regular expressions are not part
of the standard library.
 
D

Dann Corbit

Mahendra Kutare said:
Or do we need to have any specific library ?

I am more interested in knowing if we can do string pattern matching
regular expression processing with C.

It's a FAQ:

13.7: I need some code to do regular expression and wildcard matching.

A: Make sure you recognize the difference between classic regular
expressions (variants of which are used in such Unix utilities
as ed and grep), and filename wildcards (variants of which are
used by most operating systems).

There are a number of packages available for matching regular
expressions. Most packages use a pair of functions, one for
"compiling" the regular expression, and one for "executing" it
(i.e. matching strings against it). Look for header files named
<regex.h> or <regexp.h>, and functions called regcmp/regex,
regcomp/regexec, or re_comp/re_exec. (These functions may
exist in a separate regexp library.) A popular, freely-
redistributable regexp package by Henry Spencer is available
from ftp.cs.toronto.edu in pub/regexp.shar.Z or in several other
archives. The GNU project has a package called rx. See also
question 18.16.

Filename wildcard matching (sometimes called "globbing") is done
in a variety of ways on different systems. On Unix, wildcards
are automatically expanded by the shell before a process is
invoked, so programs rarely have to worry about them explicitly.
Under MS-DOS compilers, there is often a special object file
which can be linked in to a program to expand wildcards while
argv is being built. Several systems (including MS-DOS and VMS)
provide system services for listing or opening files specified
by wildcards. Check your compiler/library documentation. See
also questions 19.20 and 20.3.
 
I

Ian Collins

Jack said:
I disagree, one most certainly can.

There are no functions for doing this in the standard library, so one
would have to either write them, or find a library that already
contained them. But such a library could be written in strictly
conforming C, at least for the ASCII character set.
Didn't you see the clarification I posted an hour earlier?
 
C

CBFalconer

Don said:
Quite possibly not, since Usenet is a best-effort, asynchronous
distribution system that makes absolutely no promises whatsoever
that any specific message will reach any given server in any
particular amount of time. Depending on the route it has to take,
the newsgroup(s) it's posted to, the time of day it was posted,
and many other variables including how the destination server
(and any servers between the one you posted on and the
destination) is configured, a message you post to your news
server might be seen on a different server within seconds. Or it
could take anywhere from minutes to weeks to get there. Assuming
it ever makes the trip at all...

Precisely. And, since the normal transmission time is often
measured in seconds or minutes, most people totally forget this
fact, fail to properly quote, etc. etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,055
Members
48,769
Latest member
Clifft

Latest Threads

Top