1

In C#, I want to use a regular expression to match words within [[XXX]].

ex;

Vennligst betal følgende faktura: Fakturanr: [[INVOICENO]], Beløp: [[AMOUNT]], Forfall: [[DUEDATE]], KID: [[KID]] til konto: [[GYMACCOUNT]]. Mvh Aktiv365

Alexander
  • 1,939
  • 17
  • 29
  • did you actually try to look it up? – Alexander Nov 16 '15 at 05:19
  • Welcome to SO. Your question sort of reads as a set of requirements. Any code to show? What research have you done? These things will help us help you. Good luck! _[How do I ask a good question?](http://stackoverflow.com/help/how-to-ask)_ – MickyD Nov 16 '15 at 05:45

4 Answers4

2

You can use lookarounds to match the word inside square brackets.

(?<=\[\[)\w+(?=]])
  • \w+ one or more word characters
  • (?<=\[\[) if preceded by [[
  • (?=]]) if followed by ]]

See demo at regexstorm

bobble bubble
  • 11,625
  • 2
  • 24
  • 38
1

You can use this pattern.

Regex r = new Regex(@"\[\[.+?]]");

var matches = r.Matches(input);
M.kazem Akhgary
  • 17,601
  • 7
  • 53
  • 108
0

try

Use escape character in regex :

 \[\[xxx\]\] in regex
Vanarajan
  • 963
  • 1
  • 10
  • 33
0

You can try the https://regex101.com/

and May be this expression do

\[\[.*\]\]
Ravi Kumar Mistry
  • 1,009
  • 1
  • 13
  • 22