Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #36630

Re: indexOf do not behave as i expected?

Newsgroups comp.lang.javascript
Subject Re: indexOf do not behave as i expected?
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <21c9b272-81ba-4da2-9c25-378447e0d635@googlegroups.com>
Date 2019-05-22 12:38 +0200
Message-ID <XnsAA578086F3284eejj99@194.109.6.166> (permalink)

Show all headers | View raw


Jonas_Thornvall <jonas.thornvall@gmail.com> wrote on 22 May 2019 in 
comp.lang.javascript:

>      while(!LASTBANK) {
>             var bnkSTART = ATXT.indexOf("[",LB);
>             var bnkEND = ATXT.indexOf("]",LB);
> 

Time to learn Regex!

<script> 

'use strict';

let s = '[blah1] blah2 [blah3] blah4 [blah5] blah6' ;

let rgx = /\[(.*?)\]/g;

let matches;

let output = [];

while (matches = rgx.exec(s)) {
    output.push(matches[1]);
};

console.log(output);

// Array(3)
// 0: "blah1"
// 1: "blah3"
// 2: "blah5"
// length: 3

</script> 



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

indexOf do not behave as i expected? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-22 02:38 -0700
  Re: indexOf do not behave as i expected? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-05-22 12:38 +0200
    Re: indexOf do not behave as i expected? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-22 03:53 -0700
    Re: indexOf do not behave as i expected? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-22 04:26 -0700
      Re: indexOf do not behave as i expected? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-22 04:38 -0700
        Re: indexOf do not behave as i expected? JJ <jj4public@vfemail.net> - 2019-05-22 19:34 +0700
          Re: indexOf do not behave as i expected? Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-05-22 13:48 +0000
    Re: indexOf do not behave as i expected? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-05-22 22:28 +0200
  Re: indexOf do not behave as i expected? "R.Wieser" <address@not.available> - 2019-05-23 07:59 +0200
    Re: indexOf do not behave as i expected? "R.Wieser" <address@not.available> - 2019-05-23 10:47 +0200

csiph-web