Why is the following regex not working in C using regcomp

前端 未结 2 435
滥情空心
滥情空心 2021-01-29 00:30

I have the following regex to match the last pair of braces in a string,

.+(?={)(.+)(?=})

The example string is,

abc{abc=bcd}{g         


        
相关标签:
2条回答
  • 2021-01-29 01:09

    Anyway, regcomp uses POSIX BRE or ERE, which doesn't support look-ahead or look-behind.

    .+{(.+)}
    

    Grab the string you want from group index 1.

    DEMO

    0 讨论(0)
  • 2021-01-29 01:11

    Uses an anchor to specify the pattern should match when at the end of a line.

    (?<=[{]).*(?=[}]$)

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