regex - Rolling Regexp in Ruby -


if have string "ababa" how can find indices string "aba" exists? in instance, want return 0 , 2 because have (aba)ba , ab(aba).

edit: lookahead kind of works (or did in ruby)... i'm having trouble reimplementing in javascript. throwing infinite loop:

str = 'ababa', re = /(?=aba)/g while ((match = re.exec(str)) !== null) {   console.log(match) } 

thanks!

use lookahead instead of capturing string.

(?=aba) 

try this.see demo.

https://regex101.com/r/sj9gm7/35

var re = /(?=aba)/g; var str = 'ababa'; var subst = '';  var result = str.replace(re, subst); 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -