2

I have the following css strings that I am trying to parse using a RegExp. I understand how to split on the comma. How do I work with the result to return an array or string?

I guess I'm missing the concept of capturing groups. These are css background properties.

this will split the commas /,\s*/ how would I then split the spaces to return a 2d array.

value = "0% 100%, 0% 0%, 100% 0%, 50% 50%";

This works great to get the first url. I would like to split on the comma /,\s*/ then split that result with /((?<=\")[^\"]*(?=\"))/

value = 'url("img/army_ant.png"),url("img/ants_menuNavButtton.png"),url("img/dirtbgtile.png")';

Thanks.

I am working in AS3 but JavaScript RegExp work just as well.

Thanks

2
  • 1
    for regex questions, explicit examples of input, expected output are the most helpful. Commented Oct 29, 2015 at 5:29
  • JS does not support look-behinds. Commented Oct 29, 2015 at 6:52

1 Answer 1

0

You can use the map function. For the first case:

var value = "0% 100%, 0% 0%, 100% 0%, 50% 50%";
var final = value.split(/,\s*/).map(function(e) { return e.split(/\s+/); })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.