[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.
Bruno
- Plain text matching with regex: RE_PLAIN, Reuben Thomas, 2010/09/14
- Re: Plain text matching with regex: RE_PLAIN, Eric Blake, 2010/09/14
- Re: Plain text matching with regex: RE_PLAIN, Reuben Thomas, 2010/09/14
- Re: Plain text matching with regex: RE_PLAIN, Bruno Haible, 2010/09/14
- Re: Plain text matching with regex: RE_PLAIN, Reuben Thomas, 2010/09/17
- Re: new module 'regex-quote', Bruno Haible, 2010/09/18
- Re: new module 'regex-quote', Reuben Thomas, 2010/09/18
- Re: new module 'regex-quote', Reuben Thomas, 2010/09/20
- Re: new module 'regex-quote', Eric Blake, 2010/09/20
- Re: new module 'regex-quote',
Bruno Haible <=
- Re: new module 'regex-quote', Eric Blake, 2010/09/20
- Re: new module 'regex-quote', Bruno Haible, 2010/09/20
- Re: new module 'regex-quote', Bruce Korb, 2010/09/20
- Re: new module 'regex-quote', Reuben Thomas, 2010/09/20
- Re: new module 'regex-quote', Bruno Haible, 2010/09/20
- Re: new module 'regex-quote', Reuben Thomas, 2010/09/21
- Re: new module 'regex-quote', Bruno Haible, 2010/09/25
- Re: new module 'regex-quote', Reuben Thomas, 2010/09/29
- Re: new module 'regex-quote', Bruno Haible, 2010/09/25
- Re: new module 'regex-quote', Reuben Thomas, 2010/09/29