JavaScript Regex extracting multiple matches for string [duplicate] regex extract multiple matches,regex extract multiple values,regex extract

You cannot get the direct result from match, but it is possible to produce the result via RegExp.exec and with some modification to the regex:

var regex = /A[0-9]+B[0-9]+Y(?=(:A[0-9]+B[0-9]+Y))/g;
var input = 'A1B1Y:A1B2Y:A1B3Y:A1B4Z:A1B5Y:A1B6Y:A1B7Y:A1B8Z:A1B9Y:A1B10Y:A1B11Y'
var arr;
var results = [];

while ((arr = regex.exec(input)) !== null) {
    results.push(arr[0] + arr[1]);
}

I used zero-width positive look-ahead (?=pattern) in order not to consume the text, so that the overlapping portion can be rematched.

Actually, it is possible to abuse replace method to do achieve the same result:

var input = 'A1B1Y:A1B2Y:A1B3Y:A1B4Z:A1B5Y:A1B6Y:A1B7Y:A1B8Z:A1B9Y:A1B10Y:A1B11Y'
var results = [];

input.replace(/A[0-9]+B[0-9]+Y(?=(:A[0-9]+B[0-9]+Y))/g, function ($0, $1) {
    results.push($0 + $1);
    return '';
});

However, since it is replace, it does extra useless replacement work.

Answer:1

In my tests, sometimes I get timeouts, and it would be very useful to see what where the promises that were pending before the timeout, so that I know what promises have the most chances of being in ...

In my tests, sometimes I get timeouts, and it would be very useful to see what where the promises that were pending before the timeout, so that I know what promises have the most chances of being in ...

I've got following piece of html code: <div class="header-menu hide-for-small"> <ul id="primary-menu" class="subtext"> <li id="menu-item-993"><a>X</a></li&...

I've got following piece of html code: <div class="header-menu hide-for-small"> <ul id="primary-menu" class="subtext"> <li id="menu-item-993"><a>X</a></li&...

  1. change hover element
  2. change element on hover css
  3. change child element hover
  4. change color element hover
  5. change another element on hover
  6. change other element on hover
  7. change other element on hover css
  8. change different element on hover
  9. change child element on hover css
  10. change another element on hover css
  11. change pseudo element on hover
  12. change after element on hover
  13. change element color when hover css
  14. change different element on hover css
  15. change before element on hover
  16. change inner element on hover
  17. change parent element on hover
  18. change cursor on element hover
  19. change element content on hover
  20. change element size on hover

I'm calling js function every 2 seconds where on certain condition I want to update div on the view. <div id="ball_{{ballIndex}}">{{ball}}</div> on ng controller var myCounter = ...

I'm calling js function every 2 seconds where on certain condition I want to update div on the view. <div id="ball_{{ballIndex}}">{{ball}}</div> on ng controller var myCounter = ...

My function below returns an object containing the sorted playerPoints passed in via the "array of objects" parameter. Without modifying the passed in array, is there a more efficient/performant way ...

My function below returns an object containing the sorted playerPoints passed in via the "array of objects" parameter. Without modifying the passed in array, is there a more efficient/performant way ...