修改此正则表达式:{([^ \]]*)}接受\]

use*_*048 3 php regex pcre escaping

我有这个正则表达式:

{([^\]]*)} // any character except ']' but i want it to accept also '\]' this combination of 2chars
Run Code Online (Sandbox Code Playgroud)

'Lorem Ipsum is simply] dummy text' should return => 'Lorem Ipsum is simply' (and this ones does) but
'Lorem Ipsum is simply\] dummy text' => should return all the text because the ']' is escaped
Run Code Online (Sandbox Code Playgroud)

希望它有意义

Mar*_*ers 7

您可以使用替换:

(?:\\\]|[^\]])*
Run Code Online (Sandbox Code Playgroud)