-2

For example this regular expression will capture everything inside of curly braces: {[^}]+} so in this string "Hello how {are} you?" the word "are" will be captured.

Similarly, this captures everything in square brackets: [(.*?)]

I don't understand the similarity between the two and can't figure out how to capture text inside other identifiers. For example, what if I wanted to capture everything inside of characters like this: ^{this}^ in which I want everything inside of ^{ }^ or like this #[ ]#.

Cole Perry
  • 197
  • 21

1 Answers1

0

I think you are looking for following regex

.*(?:\[|\{)(.*?)(?=\]|\}).*

Then you need to consider Group 1.

(?:) to Non-capturing groups and drop them from the result. Defining both { and [ so that these will not be captured.

X(?=Y) Positive lookahead X if followed by Y

Kousik Mandal
  • 686
  • 1
  • 6
  • 15