Home > OS >  How to get all the words in a string starting with '{' and ending with '}' in Ja
How to get all the words in a string starting with '{' and ending with '}' in Ja

Time:02-26

I am new to regexs. I have this :

  '@time-transform{
     [bg:red;c:white]
     [bg:black]
     [bg:white;c:black]
   }'

I want the part inside curly brackets.

CodePudding user response:

You can split the string by regex:

const result = input.split(/({|})/)[2];

CodePudding user response:

Seems it can be also done without regex tho.

const text = '@time-transform{[bg:red;c:white][bg:black][bg:white;c:black]}';

const result = text.substring(text.indexOf('{')   1, text.indexOf('}'));

console.log(result);
// logged: '[bg:red;c:white][bg:black][bg:white;c:black]' (string)
  • Related