Skip to content

Strange behavior with lookarounds at the begin or end of a regexp #864

@Ferry612

Description

@Ferry612

I’ve observed a – in my eyes – strange behavior of PCRE when using lookarounds at the begin or end of a regular expression.

See this example:

/(?<=\d\d).+/ =~ ’42 ist the answer.‘

This yields as match result: „ ist the answer.“ (with a leading blank).

Until now, I thought that lookarounds do not capture anything, but in this case it does – ‘42’ is captured by the lookbehind and does not appear as match result although it is part of the match of „.+“.

The same also occurs with a lookahead at the end:

/.+(?=\d\d)/ =~ „The answer is 42.“

yields „The answer is „ (with a trailing blank).

The digits and the dot are captured by the lookahead and are not returned in the match of „.+“.

Is this a bug? Why PCRE behaves like this ?

Kind greetings from Vienna,

Ferry

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion from a user

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions