0

I think this question should be an easy one. I use a regex expression which, actually is:

 str_pow = str_input.match(/(?:x)[^][+-]?\d{1,4}\s/g);

The problem lays in that I need only numbers, though they're still of string type(don't think about this), but not this part x^. Currently the how str_pow looks like is this

enter image description here

This means two things: I've to either edit my regex mask, or to find a way to cut the first two "x^" characters of for each element i of the array. Can you help me to do this, because I tried to slice but it was an unsuccessful experiment.

4
  • What do you want to match actually? Commented Oct 18, 2015 at 14:13
  • just the numbers after ^x but I need the ^x part in order to pick the proper values from the string Commented Oct 18, 2015 at 14:13
  • str_pow appear to be array , not string ? What is expected result ? array of digits ? Commented Oct 18, 2015 at 14:15
  • I think it's the console which says it's an array. Indeed, the type of this array is string => it is a string array filled with x^some_numbers_here -elements and I need to cut those x^ in order to parse the some_numbers_here part later and convert it into an integer for further calculations. Commented Oct 18, 2015 at 14:18

1 Answer 1

2

You can loop the array:

var a = ["x^5 ", "x^4 ", "x^2 ", "x^1 "];

for(var i = 0; i< a.length; i++) {
    a[i] = parseInt(a[i].substring(2, a[i].length).trim(), 10);
}
console.log(a);
Sign up to request clarification or add additional context in comments.

4 Comments

what this ,10 stands for?
aha, ok, it is the numerical system... I'm testing right now 1 mom
Thank you very much, it works completely fine. Thanks, again. :)

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.