the same regex but different results on Linux and Windows only C++

后端 未结 1 719
滥情空心
滥情空心 2020-12-07 04:14

I have this pattern for my command-line program:
^s?([/|@#])(?:(?!\\1).)+\\1(?:(?!\\1).)*\\1(?:(?:gi?|ig)?(?:\\1\\d\\d?)?|i)?$
based on ECMAScript 262 f

相关标签:
1条回答
  • 2020-12-07 05:08

    There seems to have been a bug in GCC that got fixed in version 5.4. My guess is you are running an older version on your Windows set-up.

    See the difference in output in:

    • Version 4.9: "okey" (wrong)
    • Version 5.4: "no" (right)

    It does not seem to make a difference whether boost is included or not.

    The bug is related to (?!\\1), as replacing it by (?![/]) (in both instances) solves the issue, but obviously that would limit the regular expression for use with the / delimiter only:

    • Version 4.9 with (?![1]): "no" (correct)

    Also, the bug appears with this simple regular expression: (.)((?!\\1).) which should reject an input like aa:

    • Version 5.4: "no" (right)
    • Version 4.9: "okey" (wrong)

    Conclusion: make sure to install GCC version 5.4 or higher.

    0 讨论(0)
提交回复
热议问题