Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #4335

Re: how to use regex library

From cri@tiac.net (Richard Harter)
Newsgroups comp.lang.c
Subject Re: how to use regex library
Date 2011-05-19 16:02 +0000
Message-ID <4dd53966.41340264@text.giganews.com> (permalink)
References (1 earlier) <slrnit6ffp.11pj.usenet-nospam@guild.seebs.net> <pan.2011.05.18.10.41.08.923000@Owner-PC.com> <ir0cca$ph8$1@dont-email.me> <0.be25e6de4a57b82abacc.20110518200015BST.87tycru94w.fsf@bsb.me.uk> <slrnit87q8.21c3.usenet-nospam@guild.seebs.net>

Show all headers | View raw


On 18 May 2011 19:44:39 GMT, Seebs <usenet-nospam@seebs.net> wrote:

>On 2011-05-18, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>> James Kuyper <jameskuyper@verizon.net> writes:
>><snip>
>>> Please explain what you want to do. If your answer contains, anywhere
>>> within it, the words "regex", "library", "henry", "spencer", "RE", or
>>> "try.c", then you're still answering the wrong question - please rewrite it.
>
>> I agree that the OP has not answered the question the Seebs asked, but I
>> don't see why he or she must answer it.  What's wrong with asking (in a
>> round about way) "can you help me use the XYZ library?".
>
>The lack of any indication of what the problem is.  Consider the following
>questions I might have about a regex library:
>
>* How do I link this with my program?
>* Why does a binary I built with this not run on other machines?
>* How do I build with this if I don't have root privileges for the install?
>* Any time I try to refer to the data types for this library, I get
>  complaints about unknown types, what am I doing wrong?
>* I can't understand the difference between basic and extended regular
>  expressions, can someone tell me?
>* Do I have to call regfree() every time I use a regular expression, or just
>  once when I'm done with it?
>* If I never call regfree(), do I have a memory leak?
>* What does regcomp() actually do?
>* What arguments should I provide to regcomp()?
>* What's the difference between regcomp() and regexec()?

In short, these are the kinds of questions you are prepared to answer.
However this is of no help to the OP, who is obviously muddling around
at the very beginning of understanding how to the said package.
  
>
>All of these might be ways in which I needed help using it.  I could write
>a (short) book of information on using Spencer's regex library, and still not
>have hit the specific problem the OP might or might not have been having.
>
>What's lacking is any indication of what the OP wants to do, and what part
>of it isn't working or making sense.  We don't know whether the OP has read
>the documentation (although I'm guessing not), or ever reads documentation,
>or actually knows what a regex is, or is on a platform where these functions
>are not a part of the system library, or anything.
>
>No place to start.

Of course there is.  Below I quote Mark Bluemel's response.  It is an
excellent example of how to answer such a query.  He was helpful.  You
are not.  Of course, there is no reason that you should be; we each of
us have our own last.  Still, that is not the OP's fault.

BEGIN QUOTATION

I didn't, but having looked at it briefly, I think I could do so now.

Have you tried reading the manual page? The principles seem fairly 
straightforward - the crucial thing you need to understand is that
your 
expectation is wrong.

 > I expected to send RE pattern
 > and target string to the library, then it send me back with either
 > match was found of not, if found send me back position in the
 > target string and length of matched string.

Why did you expect this? You should try and understand the API as 
implemented and documented rather than what you hope it might be.

Key points (illustrated from the example program):-

1) the regular expression needs to be compiled before use

	#include <regexp.h>
	regexp *r;
	r = regcomp(argv[1]);	/* compile RE from command line*/

2) there may be multiple parenthesized expressions to be matched, so
you 
can't expect to only have a single position and length.
(There can be up to NSUBEXP that the library will handle, NSUBEXP 
defaults to 10, but can be changed by recompilation)

	int i;
	/* did the string from the command line match ? */
	i = regexec(r, argv[2]);
	printf("%d", i);
	for (i = 1; i < NSUBEXP; i++)
	/* check start and end pointers for matched expressions */
		if (r->startp[i] != NULL && r->endp[i] != NULL)
			printf(" \\%d", i);

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-17 23:11 -0400
  Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-18 03:33 +0000
    Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-18 06:41 -0400
      Re: how to use regex library James Kuyper <jameskuyper@verizon.net> - 2011-05-18 08:00 -0400
        Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-18 20:00 +0100
          Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-18 19:44 +0000
            Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-19 00:43 +0100
              Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 00:52 +0000
                Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-18 22:04 -0400
                Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 02:21 +0000
                Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-19 04:04 +0100
                Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 03:14 +0000
                Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-19 12:03 +0100
                Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 14:37 +0000
                Re: how to use regex library Geoff <geoff@invalid.invalid> - 2011-05-19 11:29 -0700
                Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 19:08 +0000
                Re: how to use regex library Geoff <geoff@invalid.invalid> - 2011-05-19 12:11 -0700
                Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-20 12:55 -0400
                Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-19 04:01 +0100
            Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-19 16:02 +0000
              Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 16:34 +0000
                Re: how to use regex library Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-19 13:59 -0700
                Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 22:06 +0000
                Re: how to use regex library Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-24 02:03 -0700
                Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-20 13:14 -0400
                Re: how to use regex library Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-24 02:16 -0700
            Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-19 14:37 -0400
          Re: how to use regex library James Kuyper <jameskuyper@verizon.net> - 2011-05-18 19:44 -0400
            Re: how to use regex library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-19 03:49 +0100
              Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 03:03 +0000
                Re: how to use regex library Ike Naar <ike@iceland.freeshell.org> - 2011-05-19 06:48 +0000
                Re: how to use regex library James Kuyper <jameskuyper@verizon.net> - 2011-05-19 05:58 -0400
                Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 14:37 +0000
            Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-19 14:48 -0400
              Re: how to use regex library Shao Miller <sha0.miller@gmail.com> - 2011-05-19 15:05 -0400
      Re: how to use regex library Mark Bluemel <mark_bluemel@pobox.com> - 2011-05-18 13:36 +0100
        Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-18 13:13 -0400
        Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-18 22:13 -0400
          Re: how to use regex library Mark Bluemel <mark_bluemel@pobox.com> - 2011-05-19 08:55 +0100
            Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-19 07:59 -0400
              Re: how to use regex library Keith Thompson <kst-u@mib.org> - 2011-05-19 08:50 -0700
              Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-19 15:12 -0400
                Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 19:40 +0000
                Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-19 20:58 +0000
                Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-19 22:06 +0000
                Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-20 01:01 +0000
                Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-20 01:57 +0000
                Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-20 13:27 -0400
                Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-20 13:08 -0400
                Re: how to use regex library Dr Nick <3-nospam@temporary-address.org.uk> - 2011-05-20 18:54 +0100
                Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-20 19:14 +0000
                Re: how to use regex library Dr Nick <3-nospam@temporary-address.org.uk> - 2011-05-21 00:04 +0100
                Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-23 12:42 -0400
                Re: how to use regex library Dr Nick <3-nospam@temporary-address.org.uk> - 2011-05-23 20:16 +0100
                Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-23 21:16 +0000
                Re: how to use regex library Kenneth Brody <kenbrody@spamcop.net> - 2011-05-24 12:08 -0400
                Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-25 05:27 +0000
                Re: how to use regex library Michael Press <rubrum@pacbell.net> - 2011-05-22 21:41 -0700
                Re: how to use regex library cri@tiac.net (Richard Harter) - 2011-05-23 21:33 +0000
      Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-18 16:03 +0000
    Re: how to use regex library Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-05-18 14:05 +0000
  Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-20 22:06 -0400
    Re: how to use regex library Seebs <usenet-nospam@seebs.net> - 2011-05-21 03:49 +0000
      Re: how to use regex library Owner <Owner@Owner-PC.com> - 2011-05-21 20:25 -0400
    Re: how to use regex library Shao Miller <sha0.miller@gmail.com> - 2011-05-21 13:17 -0500

csiph-web