{"thread":{"id":"49484","subject":"[PATCH] [Outreachy] git/userdiff.c fix regex pattern error","startedAt":"2018-10-04T11:30:23Z","lastAt":"2018-10-12T08:42:03Z","messageCount":9,"participants":["Ananya Krishna Maram","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"359617","messageId":"20181004113015.GA30901@manohar-ssh","threadId":"49484","inReplyTo":null,"subject":"[PATCH] [Outreachy] git/userdiff.c fix regex pattern error","fromName":"Ananya Krishna Maram","fromEmail":"ananyakittu1997@gmail.com","sentAt":"2018-10-04T11:30:15Z","receivedAt":"2018-10-04T11:30:23Z","isPatch":true,"sender":{"key":"ananyakittu1997@gmail.com","avatar":null},"body":"the forward slash character should be escaped with backslash. Fix\nUnescaped forward slash error in Python regex statements.\n\nSigned-off-by: Ananya Krishna Maram<ananyakittu1997@gmail.com>\n---\n userdiff.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/userdiff.c b/userdiff.c\nindex f565f6731..f4ff9b9e5 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -123,7 +123,7 @@ PATTERNS(\"python\", \"^[ \\t]*((class|def)[ \\t].*)$\",\n \t /* -- */\n \t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n \t \"|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?\"\n-\t \"|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n+\t \"|[-+*\\/<>%&^|=!]=|\\/\\/=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n \t /* -- */\n PATTERNS(\"ruby\", \"^[ \\t]*((class|module|def)[ \\t].*)$\",\n \t /* -- */\n-- \n2.17.1\n\n"},{"id":"359619","messageId":"nycvar.QRO.7.76.6.1810041624290.73@tvgsbejvaqbjf.bet","threadId":"49484","inReplyTo":"20181004113015.GA30901@manohar-ssh","subject":"Re: [PATCH] [Outreachy] git/userdiff.c fix regex pattern error","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-10-04T14:26:19Z","receivedAt":"2018-10-04T14:26:18Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Ananya,\n\nthank you for taking the time to write this patch!\n\nOn Thu, 4 Oct 2018, Ananya Krishna Maram wrote:\n\n> the forward slash character should be escaped with backslash. Fix\n> Unescaped forward slash error in Python regex statements.\n> \n> Signed-off-by: Ananya Krishna Maram<ananyakittu1997@gmail.com>\n\nThat explains pretty well what you did, but I wonder why the forward slash\nneeds to be escaped? I would understand if we enclosed the pattern in\n`/<regex>/`, as it is done e.g. in Javascript, but we do not...\n\nThanks,\nJohannes\n\n> ---\n>  userdiff.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/userdiff.c b/userdiff.c\n> index f565f6731..f4ff9b9e5 100644\n> --- a/userdiff.c\n> +++ b/userdiff.c\n> @@ -123,7 +123,7 @@ PATTERNS(\"python\", \"^[ \\t]*((class|def)[ \\t].*)$\",\n>  \t /* -- */\n>  \t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n>  \t \"|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?\"\n> -\t \"|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n> +\t \"|[-+*\\/<>%&^|=!]=|\\/\\/=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n>  \t /* -- */\n>  PATTERNS(\"ruby\", \"^[ \\t]*((class|module|def)[ \\t].*)$\",\n>  \t /* -- */\n> -- \n> 2.17.1\n> \n> \n"},{"id":"359621","messageId":"CA+=o6KFN-p901GiJzj5BquU2RKCVTOKarGpjjuqsASN_uqGZSQ@mail.gmail.com","threadId":"49484","inReplyTo":"nycvar.QRO.7.76.6.1810041624290.73@tvgsbejvaqbjf.bet","subject":"Re: [PATCH] [Outreachy] git/userdiff.c fix regex pattern error","fromName":"Ananya Krishna Maram","fromEmail":"ananyakittu1997@gmail.com","sentAt":"2018-10-04T09:35:18Z","receivedAt":"2018-10-04T15:05:33Z","isPatch":true,"sender":{"key":"ananyakittu1997@gmail.com","avatar":null},"body":"On Thu, 4 Oct 2018 at 19:56, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n>\n> Hi Ananya,\n>\n> thank you for taking the time to write this patch!\n>\n> On Thu, 4 Oct 2018, Ananya Krishna Maram wrote:\n>\n> > the forward slash character should be escaped with backslash. Fix\n> > Unescaped forward slash error in Python regex statements.\n> >\n> > Signed-off-by: Ananya Krishna Maram<ananyakittu1997@gmail.com>\n>\n> That explains pretty well what you did, but I wonder why the forward slash\n> needs to be escaped? I would understand if we enclosed the pattern in\n> `/<regex>/`, as it is done e.g. in Javascript, but we do not...\n\nYou are correct, the code would execute either ways. But when I came across\nthis line, I didn't get it's meaning instantly because as per standards, forward\nslash has to be escaped. In fact when open source code is written according to\nstandards, the code will be reachable to more people.\n\nThanks,\nAnanya.\n\n> Thanks,\n> Johannes\n>\n> > ---\n> >  userdiff.c | 2 +-\n> >  1 file changed, 1 insertion(+), 1 deletion(-)\n> >\n> > diff --git a/userdiff.c b/userdiff.c\n> > index f565f6731..f4ff9b9e5 100644\n> > --- a/userdiff.c\n> > +++ b/userdiff.c\n> > @@ -123,7 +123,7 @@ PATTERNS(\"python\", \"^[ \\t]*((class|def)[ \\t].*)$\",\n> >        /* -- */\n> >        \"[a-zA-Z_][a-zA-Z0-9_]*\"\n> >        \"|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?\"\n> > -      \"|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n> > +      \"|[-+*\\/<>%&^|=!]=|\\/\\/=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n> >        /* -- */\n> >  PATTERNS(\"ruby\", \"^[ \\t]*((class|module|def)[ \\t].*)$\",\n> >        /* -- */\n> > --\n> > 2.17.1\n> >\n> >\n"},{"id":"359628","messageId":"nycvar.QRO.7.76.6.1810041718480.73@tvgsbejvaqbjf.bet","threadId":"49484","inReplyTo":"CA+=o6KFN-p901GiJzj5BquU2RKCVTOKarGpjjuqsASN_uqGZSQ@mail.gmail.com","subject":"Re: [PATCH] [Outreachy] git/userdiff.c fix regex pattern error","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-10-04T15:26:32Z","receivedAt":"2018-10-04T15:26:31Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Ananya,\n\nOn Thu, 4 Oct 2018, Ananya Krishna Maram wrote:\n\n> On Thu, 4 Oct 2018 at 19:56, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> >\n> > Hi Ananya,\n> >\n> > thank you for taking the time to write this patch!\n> >\n> > On Thu, 4 Oct 2018, Ananya Krishna Maram wrote:\n> >\n> > > the forward slash character should be escaped with backslash. Fix\n> > > Unescaped forward slash error in Python regex statements.\n> > >\n> > > Signed-off-by: Ananya Krishna Maram<ananyakittu1997@gmail.com>\n> >\n> > That explains pretty well what you did, but I wonder why the forward slash\n> > needs to be escaped? I would understand if we enclosed the pattern in\n> > `/<regex>/`, as it is done e.g. in Javascript, but we do not...\n> \n> You are correct, the code would execute either ways. But when I came across\n> this line, I didn't get it's meaning instantly because as per standards, forward\n> slash has to be escaped. In fact when open source code is written according to\n> standards, the code will be reachable to more people.\n\nI am afraid that I do not follow... Regular expressions have quite a few\nspecial characters, but forward slashes are not among them.\n\nMeaning: if we had specified the regular expression thusly (in any\nlanguage that supports them to be specified in this way):\n\n\t/|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\\\*\\\\*=?/\n\nthen I would agree that this is a bug, and needs to be fixed. But we\nspecify it as a regular C string:\n\n\t\"|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\\\*\\\\*=?\"\n\nIn this context, the backslash has an additional, nested meaning: it\nescapes special characters in a C string, too. So writing\n\n\t\"\\\\\"\n\nwill actually result in a string consisting of a single backslash. And\n\n\t\"\\n\"\n\nwould specify a string consisting of a single line feed character. Some C\ncompilers ignore incorrectly-escaped characters, i.e. \"\\/\" would simply\nexpand to the forward slash.\n\nHowever, you wanted to escape the forward slash in the regular expression.\nTo do that, you would have to write\n\n\t\"\\\\/\"\n\ni.e. specifying, in a C string, a backslash character, followed by a\nforward slash character.\n\nHowever, the regular expression would then be interpreting the backslash\ncharacter as escape character in its own right, seeing the forward slash,\nand replacing this sequence by a forward slash.\n\nBut it does not need to be escaped, when you specify the regular\nexpression the way we do. And the way we specified it is really the\nstandard when specifying regular expressions in C code, i.e. *without* the\nsuggested backslash.\n\nCiao,\nJohannes\n\n> \n> Thanks,\n> Ananya.\n> \n> > Thanks,\n> > Johannes\n> >\n> > > ---\n> > >  userdiff.c | 2 +-\n> > >  1 file changed, 1 insertion(+), 1 deletion(-)\n> > >\n> > > diff --git a/userdiff.c b/userdiff.c\n> > > index f565f6731..f4ff9b9e5 100644\n> > > --- a/userdiff.c\n> > > +++ b/userdiff.c\n> > > @@ -123,7 +123,7 @@ PATTERNS(\"python\", \"^[ \\t]*((class|def)[ \\t].*)$\",\n> > >        /* -- */\n> > >        \"[a-zA-Z_][a-zA-Z0-9_]*\"\n> > >        \"|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?\"\n> > > -      \"|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n> > > +      \"|[-+*\\/<>%&^|=!]=|\\/\\/=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n> > >        /* -- */\n> > >  PATTERNS(\"ruby\", \"^[ \\t]*((class|module|def)[ \\t].*)$\",\n> > >        /* -- */\n> > > --\n> > > 2.17.1\n> > >\n> > >\n> \n"},{"id":"359630","messageId":"CA+=o6KHxwYdYsvFDzBaG1q2jvgtN5f4LruD5k=dqei8workWfQ@mail.gmail.com","threadId":"49484","inReplyTo":"nycvar.QRO.7.76.6.1810041718480.73@tvgsbejvaqbjf.bet","subject":"Re: [PATCH] [Outreachy] git/userdiff.c fix regex pattern error","fromName":"Ananya Krishna Maram","fromEmail":"ananyakittu1997@gmail.com","sentAt":"2018-10-04T10:39:57Z","receivedAt":"2018-10-04T16:10:13Z","isPatch":true,"sender":{"key":"ananyakittu1997@gmail.com","avatar":null},"body":"On Thu, 4 Oct 2018 at 20:56, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n>\n> Hi Ananya,\n>\n> On Thu, 4 Oct 2018, Ananya Krishna Maram wrote:\n>\n> > On Thu, 4 Oct 2018 at 19:56, Johannes Schindelin\n> > <Johannes.Schindelin@gmx.de> wrote:\n> > >\n> > > Hi Ananya,\n> > >\n> > > thank you for taking the time to write this patch!\n> > >\n> > > On Thu, 4 Oct 2018, Ananya Krishna Maram wrote:\n> > >\n> > > > the forward slash character should be escaped with backslash. Fix\n> > > > Unescaped forward slash error in Python regex statements.\n> > > >\n> > > > Signed-off-by: Ananya Krishna Maram<ananyakittu1997@gmail.com>\n> > >\n> > > That explains pretty well what you did, but I wonder why the forward slash\n> > > needs to be escaped? I would understand if we enclosed the pattern in\n> > > `/<regex>/`, as it is done e.g. in Javascript, but we do not...\n> >\n> > You are correct, the code would execute either ways. But when I came across\n> > this line, I didn't get it's meaning instantly because as per standards, forward\n> > slash has to be escaped. In fact when open source code is written according to\n> > standards, the code will be reachable to more people.\n>\n> I am afraid that I do not follow... Regular expressions have quite a few\n> special characters, but forward slashes are not among them.\n>\n> Meaning: if we had specified the regular expression thusly (in any\n> language that supports them to be specified in this way):\n>\n>         /|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\\\*\\\\*=?/\n>\n> then I would agree that this is a bug, and needs to be fixed. But we\n> specify it as a regular C string:\n>\n>         \"|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\\\*\\\\*=?\"\n>\n> In this context, the backslash has an additional, nested meaning: it\n> escapes special characters in a C string, too. So writing\n>\n>         \"\\\\\"\n>\n> will actually result in a string consisting of a single backslash. And\n>\n>         \"\\n\"\n>\n> would specify a string consisting of a single line feed character. Some C\n> compilers ignore incorrectly-escaped characters, i.e. \"\\/\" would simply\n> expand to the forward slash.\n>\n> However, you wanted to escape the forward slash in the regular expression.\n> To do that, you would have to write\n>\n>         \"\\\\/\"\n>\n> i.e. specifying, in a C string, a backslash character, followed by a\n> forward slash character.\n>\n> However, the regular expression would then be interpreting the backslash\n> character as escape character in its own right, seeing the forward slash,\n> and replacing this sequence by a forward slash.\n>\n> But it does not need to be escaped, when you specify the regular\n> expression the way we do. And the way we specified it is really the\n> standard when specifying regular expressions in C code, i.e. *without* the\n> suggested backslash.\n\nAha!. this makes total sense. I was thinking from a general regular expression\npoint of view. But I should be thinking from C point of view and how C\nmight interpret this newly submitted string.\nThis explanation is very clear. Thanks for taking time to reply to my\npatch. From next time on, I will try to think from\ngit project's point of view.\n\nThanks,\nAnanya.\n\n> Ciao,\n> Johannes\n>\n> >\n> > Thanks,\n> > Ananya.\n> >\n> > > Thanks,\n> > > Johannes\n> > >\n> > > > ---\n> > > >  userdiff.c | 2 +-\n> > > >  1 file changed, 1 insertion(+), 1 deletion(-)\n> > > >\n> > > > diff --git a/userdiff.c b/userdiff.c\n> > > > index f565f6731..f4ff9b9e5 100644\n> > > > --- a/userdiff.c\n> > > > +++ b/userdiff.c\n> > > > @@ -123,7 +123,7 @@ PATTERNS(\"python\", \"^[ \\t]*((class|def)[ \\t].*)$\",\n> > > >        /* -- */\n> > > >        \"[a-zA-Z_][a-zA-Z0-9_]*\"\n> > > >        \"|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?\"\n> > > > -      \"|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n> > > > +      \"|[-+*\\/<>%&^|=!]=|\\/\\/=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n> > > >        /* -- */\n> > > >  PATTERNS(\"ruby\", \"^[ \\t]*((class|module|def)[ \\t].*)$\",\n> > > >        /* -- */\n> > > > --\n> > > > 2.17.1\n> > > >\n> > > >\n> >\n"},{"id":"359632","messageId":"nycvar.QRO.7.76.6.1810042136430.73@tvgsbejvaqbjf.bet","threadId":"49484","inReplyTo":"CA+=o6KHxwYdYsvFDzBaG1q2jvgtN5f4LruD5k=dqei8workWfQ@mail.gmail.com","subject":"Re: [PATCH] [Outreachy] git/userdiff.c fix regex pattern error","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-10-04T19:42:21Z","receivedAt":"2018-10-04T19:42:19Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Ananya,\n\nOn Thu, 4 Oct 2018, Ananya Krishna Maram wrote:\n\n> On Thu, 4 Oct 2018 at 20:56, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> >\n> > [... talking about the reason why a slash does not need to be escaped\n> > in a C string specifying a regular expression...]\n> >\n> > But it does not need to be escaped, when you specify the regular\n> > expression the way we do. And the way we specified it is really the\n> > standard when specifying regular expressions in C code, i.e. *without* the\n> > suggested backslash.\n> \n> Aha!. this makes total sense. I was thinking from a general regular expression\n> point of view. But I should be thinking from C point of view and how C\n> might interpret this newly submitted string.\n> This explanation is very clear. Thanks for taking time to reply to my\n> patch. From next time on, I will try to think from\n> git project's point of view.\n\nOf course! Thank you for taking the time to contribute this patch.\n\nMaybe you have another idea for a micro-project? Maybe there is something\nin Git that you wish was more convenient? Or maybe\nhttps://public-inbox.org/git/?q=leftoverbits has something that you would\nlike to implement?\n\nCiao,\nJohannes\n\n> \n> Thanks,\n> Ananya.\n> \n> > Ciao,\n> > Johannes\n> >\n> > >\n> > > Thanks,\n> > > Ananya.\n> > >\n> > > > Thanks,\n> > > > Johannes\n> > > >\n> > > > > ---\n> > > > >  userdiff.c | 2 +-\n> > > > >  1 file changed, 1 insertion(+), 1 deletion(-)\n> > > > >\n> > > > > diff --git a/userdiff.c b/userdiff.c\n> > > > > index f565f6731..f4ff9b9e5 100644\n> > > > > --- a/userdiff.c\n> > > > > +++ b/userdiff.c\n> > > > > @@ -123,7 +123,7 @@ PATTERNS(\"python\", \"^[ \\t]*((class|def)[ \\t].*)$\",\n> > > > >        /* -- */\n> > > > >        \"[a-zA-Z_][a-zA-Z0-9_]*\"\n> > > > >        \"|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?\"\n> > > > > -      \"|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n> > > > > +      \"|[-+*\\/<>%&^|=!]=|\\/\\/=?|<<=?|>>=?|\\\\*\\\\*=?\"),\n> > > > >        /* -- */\n> > > > >  PATTERNS(\"ruby\", \"^[ \\t]*((class|module|def)[ \\t].*)$\",\n> > > > >        /* -- */\n> > > > > --\n> > > > > 2.17.1\n> > > > >\n> > > > >\n> > >\n> \n"},{"id":"359776","messageId":"xmqq7eiuwsm7.fsf@gitster-ct.c.googlers.com","threadId":"49484","inReplyTo":"CA+=o6KHxwYdYsvFDzBaG1q2jvgtN5f4LruD5k=dqei8workWfQ@mail.gmail.com","subject":"Re: [PATCH] [Outreachy] git/userdiff.c fix regex pattern error","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-10-06T23:41:20Z","receivedAt":"2018-10-06T23:41:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ananya Krishna Maram <ananyakittu1997@gmail.com> writes:\n\n>> But it does not need to be escaped, when you specify the regular\n>> expression the way we do. And the way we specified it is really the\n>> standard when specifying regular expressions in C code, i.e. *without* the\n>> suggested backslash.\n>\n> Aha!. this makes total sense. I was thinking from a general regular expression\n> point of view. But I should be thinking from C point of view and how C\n> might interpret this newly submitted string.\n\nIf you were thinking from a general regex point of view, you would\nnever have treated '/' as anything special, though.\n\nHistorically, some languages (like sed and perl) had an regexp match\noperator, which is denoted by enclosing a regexp inside a pair of\nslashes.  In these languages, if you use /<regexp>/ operator, and if\nyou want to match slash with the pattern, you somehow need a way to\nwrite an regexp that has slash in it.  E.g. if you want a pattern\nthat would match 'a' followed by '/' followed by 'b', your regexp\nwould look like \"a/b\", but the regexp match operation you would\nwrite in these languages would be like /a\\/b/, so that '/<regexp>/'\nparser can tell that the second slash is not a slash that signals\nthe end of the match operator.\n\nAnd then there is an unnamed misdesigned language that has a\nregmatch() function, which takes a string that contains a regular\nexpression, but somehow requires that string to begin and end with a\nslash for no justifiable reason ;-).  If you were thinking about\nregexp from that brain-dead languages' point of view, yes, you\nshould unlearn it and what Dscho gave you would make sense.\n\nC's regexp(3) library does not share such a misdesign and just takes\na regular expression as a string.  You would still need to follow\nthe quoting rules of C string literals (e.g. write a literal\ndouble-quote or backslash after an escaping backslash), but of\ncourse slash is not special there.\n\n"},{"id":"360279","messageId":"nycvar.QRO.7.76.6.1810120955090.45@tvgsbejvaqbjf.bet","threadId":"49484","inReplyTo":"xmqq7eiuwsm7.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH] [Outreachy] git/userdiff.c fix regex pattern error","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-10-12T07:57:25Z","receivedAt":"2018-10-12T07:57:32Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Sun, 7 Oct 2018, Junio C Hamano wrote:\n\n> And then there is an unnamed misdesigned language that has a\n> regmatch() function, which takes a string that contains a regular\n> expression, but somehow requires that string to begin and end with a\n> slash for no justifiable reason ;-).\n\nIt makes more sense once you realize that /<regexp>/ is a very nice\nsyntactic construct to obtain an instance of a regular expression object,\nrather than a string describing one.\n\nIn Perl it is not as obvious as in Javascript.\n\nBut in C, we do not have objects, so the way to describe a regular\nexpression is a string (which you have to compile into an opaque data\nstructure before applying it).\n\nCiao,\nJohannes\n"},{"id":"360285","messageId":"xmqqftxbblpl.fsf@gitster-ct.c.googlers.com","threadId":"49484","inReplyTo":"nycvar.QRO.7.76.6.1810120955090.45@tvgsbejvaqbjf.bet","subject":"Re: [PATCH] [Outreachy] git/userdiff.c fix regex pattern error","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-10-12T08:41:58Z","receivedAt":"2018-10-12T08:42:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> On Sun, 7 Oct 2018, Junio C Hamano wrote:\n>\n>> And then there is an unnamed misdesigned language that has a\n>> regmatch() function, which takes a string that contains a regular\n>> expression, but somehow requires that string to begin and end with a\n>> slash for no justifiable reason ;-).\n>\n> It makes more sense once you realize that /<regexp>/ is a very nice\n> syntactic construct to obtain an instance of a regular expression object,\n> rather than a string describing one.\n\nIn Perl, qr/<regexp>/ is often how you use that syntactic construct.\n\nThe unnamed misdesigned language literally uses a string whose\ncontent is /<regexp>/; iow, \n\n\tpreg_match('/a.*b/', ...)\n\nis what you see, and there is no \"regex object involved.  As far as\nthe function is concerned, it is receiving a string, that represents\na regexp.  There is no reason to require the pattern _string_ to\nbegin and end with slash, but somehow they do.\n\n> But in C, we do not have objects, so the way to describe a regular\n> expression is a string (which you have to compile into an opaque data\n> structure before applying it).\n\nAbsolutely.  C does not have regexp object literal and the literal\nyou write to represent a regexp is just a string that you would pass\nto functions like regcomp().  But at least C is not so brain-dead to\nrequire slashes on either end of that string ;-)\n"}]}