-1

Sorry to bother you all. I'm no idea about regular expression. But right now I need one very badly. I want to split text using this format {{Text}}. The "Text" can be anything. All I need is split the text at the position of {{Text}}.

Here is a sample.

var Regx = My Regx;
var String = "{{This}} is a {{test}} string to be {{spliced}} with {{Regular}} Expression";

var SplitArray = String.split(Regx);
// it will give me an array like this
// ["","is a ","string to be "," with"," Expression"]

Thank you in advance.

Edit: I solved it myself too. It is {{[^{}]+}}

Razin Abid
  • 349
  • 3
  • 15

2 Answers2

1

You can do this way

var test = "{{This}} is a {{test}} string to be {{spliced}} with {{Regular}} Expression";
var SplitArray = test.split(/\{\{.*?\}\}/);

console.log(SplitArray)
PPL
  • 6,357
  • 1
  • 11
  • 30
0

Try this:

var Regx = /\{\{.*?\}\}/;
var String = "{{This}} is a {{test}} string to be {{spliced}} with {{Regular}} Expression";

var SplitArray = String.split(Regx);
console.log(SplitArray);
// it will give me an array like this
// ["","is a ","string to be "," with"," Expression"]
sideroxylon
  • 4,338
  • 1
  • 22
  • 40