0

I would like to know the RegEx Split pattern (using C#) for a string which packed with [ and ].

For example, for the string:

This is my [word1] And this is my [word2]

I should get word1 and word2.

leppie
  • 112,162
  • 17
  • 191
  • 293
Rupesh P
  • 70
  • 7

2 Answers2

0

The following should do the trick:

\[(?<word>[^\]]*)\]

I would suggest you use some regex tool to assist you. I'm sure there are a couple but I use Expresso and it really helps with these pesky things :)

Eben Roux
  • 12,662
  • 2
  • 26
  • 47
0

Use regex /\[(.*?)\]/g. Given regex is in perl, similar is in other langauges too. Worked out here: https://regex101.com/r/zL0yW1/1

Kamal Nayan
  • 1,732
  • 20
  • 33