Reputation: 3299
I am trying to find the values of a JavaScript object using Regex.
Sample object: classes: {wrapper: 'sm-mb--1-half md-mb--2', item: 'sm-mb--quarter sm-mt--quarter'}
Expected output: sm-mb--1-half md-mb--2 sm-mb--quarter sm-mt--quarter
What I have so far /\{([A-Za-z]*:\s'.*',?\s?)*\}/gm
, but for some reason it selects everything..
Sandbox: https://regex101.com/r/hQfHKN/1
Upvotes: 1
Views: 40
Reputation: 2530
Using lookahead
and Lookbehind
you can achieve what you want.
let str = `classes: {wrapper: 'sm-mb--1-half md-mb--2', item: 'sm-mb--quarter sm-mt--quarter'}`;
const regex = /(?<={.*:).*?(?=,|})/g;
console.log(str.match(regex))
Upvotes: 1