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
  • 109,129
  • 16
  • 185
  • 292
Rupesh P
  • 37
  • 6

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,009
  • 2
  • 23
  • 43
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,682
  • 18
  • 31