[Regex] Solving this regex

The text is


I need to select everything as --key:value whatever key is and whatever value is

Morning, your question doesn’t really make much sense. Is this an assignment or something? Could you elaborate on what you are trying to accomplish.

what have you tried?

it’s not that the RegExp is awfully complicated …


hmm, i will pickup the first example to view it:

var string = "--margin:20px"
var regex = ???;

while ((cap = regex.exex(string)) {
     // cap should be { 0: "--margin:20px", 1: "margin", 2: "20px" }

Something like this?

var string = "--margin:20px"
var re = /\-\-(.*?):(\d+px)/;

// ["--margin:20px", "margin", "20px", index: 0, input: "--margin:20px"]

Please re-read the main post, you completely misunderstood it.

lol, oh dear!

Could you then maybe rephrase the question and give a more extensive example of the output you are expecting.


Almost made it an array…

var string = “–margin:20px\n”+
var regexp = /(?:(-\w+(?:-?\w):-?\d+\w+(?:[-\w;])))+/g;

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.