Regular expression to extract text between either square or curly brackets
Posted
by ObiWanKenobi
on Stack Overflow
See other posts from Stack Overflow
or by ObiWanKenobi
Published on 2010-03-08T18:24:46Z
Indexed on
2010/03/08
18:36 UTC
Read the original article
Hit count: 377
regex
Related to my previous question, I have a string on the following format:
this {is} a [sample] string with [some] {special} words. [another one]
What is the regular expression to extract the words within either square or curly brackets, ie.
{is}
[sample]
[some]
{special}
[another one]
Note: In my use case, brackets cannot be nested. I would also like to keep the enclosing characters, so that I can tell the difference between them when processing the results.
© Stack Overflow or respective owner