git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] [Outreachy] git/userdiff.c fix regex pattern error

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 6, 2018, 23:41 UTC
Message-ID
<xmqq7eiuwsm7.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<CA+=o6KHxwYdYsvFDzBaG1q2jvgtN5f4LruD5k=dqei8workWfQ@mail.gmail.com>
Ananya Krishna Maram <ananyakittu1997@gmail.com> writes:
Show 8 quoted lines
>> But it does not need to be escaped, when you specify the regular
>> expression the way we do. And the way we specified it is really the
>> standard when specifying regular expressions in C code, i.e. *without* the
>> suggested backslash.
>
> Aha!. this makes total sense. I was thinking from a general regular expression
> point of view. But I should be thinking from C point of view and how C
> might interpret this newly submitted string.

If you were thinking from a general regex point of view, you would never have treated '/' as anything special, though.

Historically, some languages (like sed and perl) had an regexp match operator, which is denoted by enclosing a regexp inside a pair of slashes. In these languages, if you use /<regexp>/ operator, and if you want to match slash with the pattern, you somehow need a way to write an regexp that has slash in it. E.g. if you want a pattern that would match 'a' followed by '/' followed by 'b', your regexp would look like "a/b", but the regexp match operation you would write in these languages would be like /a\/b/, so that '/<regexp>/' parser can tell that the second slash is not a slash that signals the end of the match operator.

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 ;-). If you were thinking about regexp from that brain-dead languages' point of view, yes, you should unlearn it and what Dscho gave you would make sense.

C's regexp(3) library does not share such a misdesign and just takes a regular expression as a string. You would still need to follow the quoting rules of C string literals (e.g. write a literal double-quote or backslash after an escaping backslash), but of course slash is not special there.

Previous: Johannes SchindelinNext: Johannes Schindelin
Message 7 of 9 in “[Outreachy] git/userdiff.c fix regex pattern error”
  1. [Outreachy] git/userdiff.c fix regex pattern errorAnanya Krishna Maram, Oct 4, 2018
  2. Johannes SchindelinOct 4, 2018
  3. Ananya Krishna MaramOct 4, 2018
  4. Johannes SchindelinOct 4, 2018
  5. Ananya Krishna MaramOct 4, 2018
  6. Johannes SchindelinOct 4, 2018
  7. Junio C HamanoOct 6, 2018
  8. Johannes SchindelinOct 12, 2018
  9. Junio C HamanoOct 12, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.