0

I'm trying to match many occurances of regex.

My text is:

aaaHello WorldaaaSomethingaaaAnother thingaaaSame thing

And I want to match aaaHello WorldaaaSomethingaaa, not aaaHello Worldaaa and aaaAnother thingaaa

I tried to write a regex like that:

/aaa.*?aaa/g

It's enough to take all possibilities of pattern like aaaHello Worldaaa, aaaHello WorldaaaSomethingaaa, aaaHello WorldaaaSomethingaaaAnother thignaaa... And so on... I can process them on the loop. I just want to take all occurances.

But I couldn't get what I want.

sundowatch
  • 3,012
  • 3
  • 38
  • 66
  • 1
    @WiktorStribiżew maybe you chose the wrong question while flagging as duplicate. That's about ruby – Christian Vincenzo Traina Sep 05 '19 at 07:46
  • No, it is correct. The question has both Ruby and JS tags and solutions. See https://jsfiddle.net/wiktor_stribizew/726mfL9b/ demo based on https://stackoverflow.com/a/56657282/3832970 answer, or https://jsfiddle.net/wiktor_stribizew/726mfL9b/2/ demo based on https://stackoverflow.com/a/34964708/3832970 answer. – Wiktor Stribiżew Sep 05 '19 at 07:46
  • 1
    @WiktorStribiżew I would have answered with a more modern approach, using the new entry method `matchAll`, which it's getting a decent support nowadays. I don't know if it would be meaningful also in the linked question – Christian Vincenzo Traina Sep 05 '19 at 07:51
  • Please add it there. Why not? – Wiktor Stribiżew Sep 05 '19 at 07:54
  • 1
    @WiktorStribiżew 's jsfiddle samples are enough for me. Thank you. – sundowatch Sep 05 '19 at 08:06

0 Answers0