0

I have written the following regex:

^project\(.+?version\s*:\s*'(.+?)'.*\)$

The first capture group will grab 0.9.20 from the following block of text:

project(
    'waybar', 'cpp', 'c',
    version: '0.9.20',
    license: 'MIT',
    meson_version: '>= 0.50.0',
    default_options : [
        'cpp_std=c++20',
        'buildtype=release',
        'default_library=static'
    ],
)

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

I need this regex to be compatible with Extended POSIX regular expression syntax.

My best attempt is this:

^project\([^)]*version[[:space:]]*:[[:space:]]*'\([^']*\)'.*\)$

However, that means the capture group matches >= 0.50.0 instead of 0.9.20. The pattern [^)]* is not specific enough, and POSIX ERE does not have a lazy operator, ?, which means that it consumes until the line that starts with meson_version.

Jacob Birkett
  • 1,927
  • 3
  • 24
  • 49
  • How about trying `^project\(\n\s+[^\n]+\n\s+version:\s+'([^']+)',\n` **or** `^project\(\n\s+[^\n]+\n\s+version:\s+'([^']+)',` once? Using multiline option in regex101 site, here is the demo for same https://regex101.com/r/w3aQPr/1 – RavinderSingh13 Aug 01 '23 at 05:57
  • How about: [https://regex101.com/r/uVYiya/1](https://regex101.com/r/uVYiya/1) – tshiono Aug 01 '23 at 06:46

0 Answers0