Jacob Birkett
Jacob Birkett

Reputation: 2135

Convert PCRE2 to Extended POSIX RE, do I really require lazy?

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.

Upvotes: 0

Views: 83

Answers (0)

Related Questions