How do I write this regex pattern?

View other answers to this thread
Start a personal dev blog on your domain for free and grow your readership.

3.4K+ developers have started their personal blogs on Hashnode in the last one month.

Write in Markdown · Publish articles on custom domain · Gain readership on day zero · Automatic GitHub backup and more

j's photo

([\w #]+) will get all the characters between the brackets and the extra spaces.

The problem I have your specification 'this kind of pattern' providing an inconsistent data sample makes it hard to discern what you actually want.

the idea of giving examples you should at least give an expected result. either you think like a function

F(input) -> output

or at least some hint what the expectation of the result should be.

Btw in your case there are multiple solutions an they depend on scale, maybe regex is the wrong solution if you got a repeating pattern you can use cursor based buffer parsers packed into generators/coroutines.