Modify this regex: {([^ \]] *)} to accept \]

I have this regex:

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



'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


hope it makes sense


source to share

2 answers

You can use alternation:





I would go with:

'~(?:[^\\\\\\]]*|\\\\.)*~' // (?:[^\\\]]|\\.)*


Contrary to Marks answer, this allows for parsing [\\]]

as \\

, which will give you the ability to use \

as a universal escape character for more than \]




All Articles