Building on this question: Regular expression to extract text between square brackets
this is a [sample] string with [some] special words. [another one]
I need to extract the text between [sample] and [some] plus the two boundaries too. In other word I want the regex that matches [sample] string with [some]
Try this:
You just need to escape the square brackets and use a lazy match between your markers.
See it here on Regexr.
If the text can be on several rows, you need to enable the dotall mode additionally with the
smodifier:this makes the
.also match newline characters, what it is not doing by default.See it here on Regexr