title: GtkSourceView - Gedit: regex matching discrepancy
body: <p>I try to use this RegEx <code>^(\[\^)([^\]\s\p{C}]+)(\])\ (\P{C}*(?:\n(?!\n[\[\n])\P{C}*)*)</code> in <a href="https://gitlab.com/pninim.org/dar/dar-syntax/-/blob/master/dar.lang#L382" rel="nofollow noreferrer">dar.lang</a> (located at <code>/usr/share/gtksourceview-3.0/language-specs</code>) to capture <a href="https://gitlab.com/pninim.org/dar/dar-syntax/-/blob/master/syntax.dar#L219" rel="nofollow noreferrer">footnotes with multiple paragraphs</a> (that i.a. terminate with 2 empty lines, i.e. 3 <code>\n</code>).</p>
  <p>When I open Gedit I see that this RegEx in <code>dar.lang</code> highlights only the first paragraph of the [^1]... footnote (ignoring the last two):</p>
  <p><a href="https://i.stack.imgur.com/cdhHn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cdhHn.png" alt="enter image description here" /></a></p>
  <p>However when I use the very same RegEx in the Gedit's &quot;Find&quot; dialog (need to press the magnifying glass icon and activate &quot;Match as Regular Expression&quot;) then it matches perfectly:</p>
  <p><a href="https://i.stack.imgur.com/nRhMA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nRhMA.png" alt="enter image description here" /></a></p>
  <p>I get the same results even if I replace both occurrences of <code>\P{C}*</code> with <code>.*</code> in the RegEx...</p>
  <p>How should I change <code>dar.lang</code> so it also captures footnotes with multiple paragraphs the same way Gedit's Find does? (<a href="https://regex101.com/r/Zl3te8/1" rel="nofollow noreferrer">regex101</a> behaves correctly just as Gedit's Find dialog).</p>
  <p><strong>Update:</strong></p>
  <p>It looks like somebody had a <a href="https://www.reddit.com/r/gnome/comments/csjpxk/problem_writing_own_syntax_highlighting_for/" rel="nofollow noreferrer">similar problem</a>. A (working) recommendation was to match empty line <code>^$</code> instead of <code>\n</code>, because GtkSourceView's syntax engine is line based (i.e. &quot;regexes only have access to one line of text at a time&quot;).</p>
  <p>However I also saw people saying that the syntax engine uses PCRE and once I run the <code>syntax.dar</code> file through <code>grep --perl-regexp</code>:</p>
  <pre class="lang-sh prettyprint-override"><code>wget https://gitlab.com/pninim.org/dar/dar-syntax/-/raw/master/syntax.dar
  grep --perl-regexp '^(\[\^)([^\]\s\p{C}]+)(\])\ (\P{C}*(?:\n(?!\n[\[\n])\P{C}*)*)' syntax.dar
  </code></pre>
  <p>I got this:</p>
  <pre><code>[^a] Sentence of a long margin note's body that refers to the word &quot;paragraph&quot;.
  [^1] Sentence of the first paragraph of the footnote. Sentence of the first paragraph of the footnote. Sentence of the first paragraph of the footnote. Sentence of the first paragraph of the footnote.
  [^b] Footnote at the end of the file. Footnote at the end of the file. Footnote at the end of the file.
  </code></pre>
  <p>So on the other hand it looks like standard PCRE behavior...</p>