开发者

regex for { } within ' 's

开发者 https://www.devze.com 2023-02-21 20:25 出处:网络
An example, I have a string that contains let\'s say: 开发者_运维技巧 function main { // TODOprint \'hello {cmd get world}

An example,

I have a string that contains let's say:

开发者_运维技巧

function main {

// TODO print 'hello {cmd get world} world {nice}!'s asdads

}

How can I select only the words that are in within {}'s and that are inside a ''string. This example would retrieve the output:

{cmd get world; nice}

thanks a lot!


(?<='[^']+\{)[^\{\}]+(?=\}[^']+')

Should do the trick.

Edit: Updated regex to use lookbehind and -aheads.

Edit 2: Regex now matches only the text inside the braces and nothing else.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号