1

I need to get all substrings that are placed between 2 signs.

For example substrings placed between ] and [:

abcabc]substrings[kkkkkkk]iwant[12345]tohave[!@#$%]

and I get: substrings iwant tohave

I tried (?<=\])(.*)(?=\[) but it returns substrings[kkkkkkk]iwant[12345]tohave.

cramopy
  • 3,459
  • 6
  • 28
  • 42
mako
  • 21
  • 3

2 Answers2

1

Your regex would need to be (?<=\])(.*?)(?=\[).

Note the added ? sign to match as few as possible.

Then you have to combine the (at the moment) three matches with spaces and you will get the output you want!

cramopy
  • 3,459
  • 6
  • 28
  • 42
0

Make it non greedy .*? or else it would match until the last [

You don't need the capturing group if you want to get the matches only:

(?<=\]).*?(?=\[)

Test

The fourth bird
  • 154,723
  • 16
  • 55
  • 70