Project

General

Profile

Actions

Bug #19379

closed

Regex: "end pattern with unmatched parenthesis" with Ruby 3.2 and interpolation

Added by renchap (Renaud Chaput) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22]
[ruby-core:112048]

Description

Sample code:

r2 = %r{#c-\w+/comment/[\w-]+}
%r{https?://[^/]+#{r2}}x

This works with Ruby 3.1:

irb(main):001:0> r2 = %r{#c-\w+/comment/[\w-]+}
irb(main):002:0> %r{https?://[^/]+#{r2}}x
=> /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x

But fails with Ruby 3.2.0:

irb(main):022:0> r2 = %r{#c-\w+/comment/[\w-]+}
irb(main):023:0> %r{https?://[^/]+#{r2}}x
(irb):23:in `<main>': end pattern with unmatched parenthesis: /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x (RegexpError)

But if I dont use interpolation, it works correctly:

irb(main):001:0> %r{https?://[^/]+#c-\w+/comment/[\w-]+}x
=> /https?:\/\/[^\/]+#c-\w+\/comment\/[\w-]+/x
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0