<p>Updated answer, according to <a href="https://docs.gitlab.com/ee/ci/jobs/job_control.html#only--except-regex-syntax" rel="nofollow noreferrer">these docs</a>:</p>
<blockquote>
<p>In GitLab 11.9.4, GitLab began internally converting the regexp used in only and except keywords to RE2.</p>
<p>RE2 limits the set of available features due to computational complexity, and some features, like negative lookaheads, became unavailable. Only a subset of features provided by Ruby Regexp are now supported.</p>
<p>From GitLab 11.9.7 to GitLab 14.9, GitLab provided a feature flag to let you use unsafe regexp syntax. We’ve fully migrated to RE2 now, and that feature flag is no longer available.</p>
</blockquote>
<p>The same is true for <code>rules</code> and <code>if</code>, like you are using.</p>
<p>TL;DR: GitLab regexps now use Google's <a href="https://github.com/google/re2/wiki/Syntax" rel="nofollow noreferrer">RE2 syntax</a>, not Ruby.</p>

CC BY-SA 4.0
2023-05-11T01:55:37.577Z
2023-05-11T01:55:37.577Z
Joe Atzberger
<p>GitLab uses <a href="https://ruby-doc.org/core-3.1.2/Regexp.html" rel="nofollow noreferrer">Ruby's core regex implementation</a> which is <a href="https://github.com/k-takata/Onigmo" rel="nofollow noreferrer">Onigmo (Oniguruma-mod)</a>. I found that from looking at the source code in Ruby's <a href="https://github.com/ruby/ruby/blob/master/regexec.c" rel="nofollow noreferrer"><code>regex.c</code></a>.</p>
<p>Official documentation is mostly here: <a href="https://github.com/k-takata/Onigmo/blob/master/doc/RE" rel="nofollow noreferrer">https://github.com/k-takata/Onigmo/blob/master/doc/RE</a></p>

CC BY-SA 4.0
2022-04-20T17:43:06.097Z
2022-04-20T17:50:32.737Z
2022-04-20T17:50:32.737Z
Evan Carroll
<p>Let's say I have a rule like this,</p>
<pre><code>- if: '$CI_COMMIT_TITLE =~ /^(fix|feat|perf|docs|build|test|ci|refactor)\S*:/'
</code></pre>
<p>It occurs to me that <code>^</code> does not match the start of any line in a multiline regex, only the start of the first line. That raises the question,</p>
<ul>
<li>Does anything match the newline?</li>
<li>Is there a multi-line regex mode?</li>
</ul>
<p>Where is the GitLab Regex documented? What Regex implementation do they use?</p>

<gitlab><gitlab-ci-runner>
What regex engine does GitLab use?
Evan Carroll
# What regex engine does GitLab use?

(Asked by: username_0 on 2022-04-20)

Let's say I have a rule like this,
- if: '$CI_COMMIT_TITLE =~ /^(fix|feat|perf|docs|build|test|ci|refactor)\S*:/'

It occurs to me that ^ does not match the start of any line in a multiline regex, only the start of the first line. That raises the question,

Does anything match the newline?
Is there a multi-line regex mode?

Where is the GitLab Regex documented? What Regex implementation do they use?

**Tags:** gitlab, gitlab-ci-runner


---

## 2 answers

### Answer by username_1 on 2023-05-11. Score: 2 | Accepted answer

Updated answer, according to [these docs](https://docs.gitlab.com/ee/ci/jobs/job_control.html#only--except-regex-syntax):

> In GitLab 11.9.4, GitLab began internally converting the regexp used in only and except keywords to RE2.
>
> RE2 limits the set of available features due to computational complexity, and some features, like negative lookaheads, became unavailable. Only a subset of features provided by Ruby Regexp are now supported.
>
> From GitLab 11.9.7 to GitLab 14.9, GitLab provided a feature flag to let you use unsafe regexp syntax. We’ve fully migrated to RE2 now, and that feature flag is no longer available.

The same is true for `rules` and `if`, like you are using.

TL;DR: GitLab regexps now use Google's [RE2 syntax](https://github.com/google/re2/wiki/Syntax), not Ruby.


---

### Answer by username_0 on 2022-04-20. Score: 1

GitLab uses [Ruby's core regex implementation](https://ruby-doc.org/core-3.1.2/Regexp.html) which is [Onigmo (Oniguruma-mod)](https://github.com/k-takata/Onigmo). I found that from looking at the source code in Ruby's [`regex.c`](https://github.com/ruby/ruby/blob/master/regexec.c).

Official documentation is mostly here: <https://github.com/k-takata/Onigmo/blob/master/doc/RE>


---

