[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new module 'regex-quote'

From: Bruno Haible
Subject: Re: new module 'regex-quote'
Date: Mon, 20 Sep 2010 18:21:54 +0200
User-agent: KMail/1.9.9

Hi Eric,

> > /* regex_quote converts a literal string to a regular expression that will
> >     look for this literal string.
> >     cflags can be 0 or REG_EXTENDED.
> >     If it is 0, the result is a Basic Regular Expression (BRE)
> >     
> > <http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03>.
> >     If it is REG_EXTENDED, the result is an Extended Regular Expression 
> > (ERE)
> >     
> > <http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04>.
> >     The result is not anchored;  if you want it to match only complete 
> > lines,
> >     you need to add "^" at the beginning of the result and "$" at the end 
> > of the
> >     result.
> Since we're already passing a flag, can we add another flag that adds 
> the ^ and $ anchors?  It's more convenient to do just one malloc (via 
> the regex_quote) that also adds the anchors, than it is to have to 
> manually call regex_quote_length, increment the result, malloc the 
> space, insert the anchors, then call regex_quote_copy.

It's an interesting suggestion. But frankly, the benefit of such an option is
small: It's straightforward, even in C, to prepend a "^" and append a "$" to 
a string. In the way you describe, or through
   regex = xasprintf ("^%s$", regex);
And adding this flag would mean that the cflags of regex_quote no longer are
a subset of the flags passed to regcomp.

So, for the moment (until there's more heavy demand for such a flag), I prefer
to address this issue only through the comments above.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]