home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!ukma!cs.widener.edu!eff!news.oc.com!mercury.unt.edu!usenet
- From: <cpearce@nemesis.acs.unt.edu> (Chris Pearce)
- Subject: Problems with regular expressions...
- Message-ID: <1992Nov9.231745.13734@mercury.unt.edu>
- Sender: usenet@mercury.unt.edu (UNT USENet Adminstrator)
- Organization: University of North Texas
- Date: Mon, 9 Nov 1992 23:17:45 GMT
- Lines: 50
-
- I stumped comp.sys.hp with this one. Maybe someone here knows what is
- happening.
-
- HP9000/425; HPUX 8.0.
-
- I'm using the routines regcomp() and regexec(). I believe that are part of
- POSIX 2. I'm trying to either match line in a file containing a keyword
- or a keyword and its argument. I'm trying to skip whitespace. I'm trying
- to match only full lines that match. I'm getting no matches.
-
- Here's a code snippet...
-
- regex_t r1, r2;
-
- init ()
- {
- r1 = regcomp (&r1, "^ *#keyword *$", REG_EXTENDED);
- r2 = regcomp (&r2, "^ *#keyword +([^ ]+) *$", REG_EXTENDED);
- }
-
- match ()
- {
- char str [256];
- regmatch_t rm [2];
-
- /* Open file, read lines into _str_ until EOF */
- ..
- if (!regexec (&r1, str, r1.re_nsub, rm, NULL))
- printf ("Matched first expression.\n
- else if (!regexec (&r2, str, r2.re_nsub, rm, NULL))
- printf ("Matched second expression.\n");
- else
- printf ("No match.\n");
- }
-
- main ()
- {
- init();
- match ();
- }
-
- I hope all that code above is typo-free: I can't go back to edit it....
- When the code runs, I get no matches. Either I'm missing something
- glaringly obvious (I hope not), I'm getting bit by some strange subtlety,
- or HPs routines are goofed. I've read the man pages (regexec, regcomp,
- and regexp(5)) carefully, but I still can't figure out the problem.
-
- Any ideas?
- ---
- Chris Pearce, cpearce@nemesis.acs.unt.edu
-