home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!news.tek.com!uw-beaver!cs.ubc.ca!destroyer!caen!sdd.hp.com!decwrl!olivea!pagesat!spssig.spss.com!news.oc.com!mercury.unt.edu!usenet
- From: cpearce@nemesis.acs.unt.edu
- Newsgroups: comp.sys.hp
- Subject: Problems with regcomp() and regexec()
- Message-ID: <1992Nov9.165816.7162@mercury.unt.edu>
- Date: 9 Nov 92 16:58:16 GMT
- Sender: usenet@mercury.unt.edu (UNT USENet Adminstrator)
- Organization: University of North Texas
- Lines: 54
-
- HPUX 8.0, HP 9000/425
-
- I'm currently trying to use the regular expression routines newly provided
- in HPUX 8.0. As far as I can tell, I'm using the routines properly, but
-
- * I'm never able to get a full-line match and
- * Subexpressions don't seem to be behaving properly.
-
- But it could just be a stupid mistake on my part also. :)
-
- Here's the structure of my program...
-
- #include <regex.h>
-
- regex_t r1, r2;
-
- void init()
- {
- regcomp (&r1, "^ *#keyword *$", REG_EXTENDED);
- regcomp (&r2, "^ *#keyword +([^ ]+) *$", REG_EXTENDED);
- }
-
- void match()
- {
- f = fopen (args...)
-
- while (!feof (f)) {
- fgets (str, 255, f);
- if (regexec (&r1, str, r1.re_nsub, rm, NULL))
- printf ("Mathced.\n");
- if (regexec (&r2, str, r2.re_nsub, rm, NULL))
- printf (Matched. sp = %x; ep = %x\n", rm [1].sp, rm [2].ep);
- }
- }
-
- main ()
- {
- init ();
- match ();
- }
-
- I stripped all the error code out... I also forgot to declare some variables
- above. str is char [255]. rm is regmatch_t [2].
-
- If I use full-line matching (where the regexp is "^...$" I never return any
- matches. By removing the full-line matching, I begin to get matches, but
- rm [1].sp and rm [1].ep are equal -- no subexpression is returned.
-
- The regular expressions themselves are supposed to match a keyword or
- a keyword and an argument. Whitespace is ignored.
-
- Am I making a fundamental error somewhere?
- --
- Chris Pearce, cpearce@nemesis.acs.unt.edu
-