Re: [PATCH] [Outreachy] git/userdiff.c fix regex pattern error
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 12, 2018, 08:41 UTC
- Message-ID
- <xmqqftxbblpl.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <nycvar.QRO.7.76.6.1810120955090.45@tvgsbejvaqbjf.bet>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 10 quoted lines
> On Sun, 7 Oct 2018, Junio C Hamano wrote: > >> And then there is an unnamed misdesigned language that has a >> regmatch() function, which takes a string that contains a regular >> expression, but somehow requires that string to begin and end with a >> slash for no justifiable reason ;-). > > It makes more sense once you realize that /<regexp>/ is a very nice > syntactic construct to obtain an instance of a regular expression object, > rather than a string describing one.
In Perl, qr/<regexp>/ is often how you use that syntactic construct.
The unnamed misdesigned language literally uses a string whose content is /<regexp>/; iow,
preg_match('/a.*b/', ...)is what you see, and there is no "regex object involved. As far as the function is concerned, it is receiving a string, that represents a regexp. There is no reason to require the pattern _string_ to begin and end with slash, but somehow they do.
> But in C, we do not have objects, so the way to describe a regular > expression is a string (which you have to compile into an opaque data > structure before applying it).
Absolutely. C does not have regexp object literal and the literal you write to represent a regexp is just a string that you would pass to functions like regcomp(). But at least C is not so brain-dead to require slashes on either end of that string ;-)