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
  • 115,091
  • 17
  • 196
  • 297
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,983
  • 2
  • 27
  • 48
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,890
  • 21
  • 34