JavaScript Regex to capture multiple array index literals inside a string regex capture multiple lines,regex capture multiple groups,regex capture

Probably dead simple for someone out there, but I want to build a regex that will search across this string:

foo[0][2]

and return

foo
0
2

in the array of matches

So far I have come up with is

\([a-z]*)(\[(\d)\])/g

which only gives back

0: "foo[0]"
1: "foo"
2: "[0]"
3: "0"

It's not repeating onto the next literal array in my string, so not hitting the [2] part.

I'm no regex ninja, and would appreciate some assistance with arriving at the correct expression I need.

Thanks

Answer:1

I think you're looking for this pattern: ([a-z]+)|(\[\d\])

console.log('foo[0][2]'.match(/([a-z]+)|(\[\d\])/g));
Answer:2

I am studying the use of reduce in javascript, and I am trying to restructure an Array of Objects in a generic way - need to be dynamic. flowchart - i get totaly lost I started with this through. ...

I am studying the use of reduce in javascript, and I am trying to restructure an Array of Objects in a generic way - need to be dynamic. flowchart - i get totaly lost I started with this through. ...

I am currently working on a Meteor application that also has a chat functionality. I want to have a list of all conversations that show the most recent message in each conversation. (Similar to ...

I am currently working on a Meteor application that also has a chat functionality. I want to have a list of all conversations that show the most recent message in each conversation. (Similar to ...

Does anyone knows how to directly call a array key of a Map Object. As shown in below code, I can map.get(arr), but not map.get([0, 1, 2, 3]) const map = new Map() const arr = [0,1,2,3] map....

Does anyone knows how to directly call a array key of a Map Object. As shown in below code, I can map.get(arr), but not map.get([0, 1, 2, 3]) const map = new Map() const arr = [0,1,2,3] map....

  1. call array object javascript
  2. call object array php
  3. call array inside object
  4. call an array object
  5. java call array object
  6. call_user_func_array object
  7. call_user_func_array object method
  8. jni call object array method
  9. call_user_func_array object oriented
  10. call_user_func_array object php
  11. array object call function
  12. python call array object

In my console's browser, when I do : console.log(typeof(typeof)) it returns an error Uncaught SyntaxError: Unexpected token ')' Why is that? Why can't I get typeof's type ?

In my console's browser, when I do : console.log(typeof(typeof)) it returns an error Uncaught SyntaxError: Unexpected token ')' Why is that? Why can't I get typeof's type ?