How to modify working regex in PCRE2 but failing in Ruby (invalid conditional pattern)

120 Views Asked by At

I've this regex:

^([A-Z]{2,}\!?) ([^(]+)(?<!\s) ?(?<BR>\()?((?(BR)[^\)]+))(?(BR)(\)))$

https://regex101.com/r/NiMbut/1

to validate input strings that follow these rules:

PREFIX description goes here (optional)
  1. PREFIX word required (all upcase, optional last char !);
  2. "description goes here" required;
  3. optional value in parentheses.

The regex has to fail if string doesn't follow correct syntax. Description submatch has to remove trailing spaces after description if there's optional value). Optional value submatch is without parentheses.

It perfectly works in PCRE2 php but fails in Ruby, but Idk why.

0

There are 0 best solutions below