How to create 2 captured groups and replace them in Intelij Idea/Android Studio?

Solution 1:

(?<name>lastBid = \d+?),(?<name2>lastBid = \d?) matches:

lastBid = 25,lastBid = 3

To match

 lastBid = 25
    lastBid = 3

you need (?<name>lastBid = \d+)\s+(?<name2>lastBid = \d)

where \s* stands for 0 or more spaces (including linebreak).


Edit according to resquest change:

  • Find: (?<name>lastBid = 2[0-5])([\s\S]*?)(?<name2>lastBid = [0-9])
  • Replace: ${name}\nrandomtext$2${name2}\nrandomtexts

Demo & explanation