RegExp insert character instead of replace

Hi,

I am trying to use the Regexp.h library by Nick Gammon to parse a string of text.
It comes in as V0417 R0393 G0432 B1014, using the library I was able to strip out everything I needed.
So now it comes out as 0393 0432 1014.

The only thing I cant figure out is how to add a period after the first character.
like this 0.393 0.432 1.014
In practice, all of the numbers will change but will always come in as 4 sets of 4 (I striped out the first set).

Any idea on how to just add the period after the first digit instead of replacing?

Thanks!

#include <Regexp.h>

void setup ()
{
  Serial.begin (9600);

  // what we are searching
  char buf [100] = "V0417 R0393 G0432 B1014";

  // for matching regular expressions
  MatchState ms (buf);

  // replace vowels
  ms.GlobalReplace ("V....", "");
  ms.GlobalReplace ("R", "");
  ms.GlobalReplace ("G", "");
  ms.GlobalReplace ("B", "");
  ms.GlobalReplace ("[.-...]", ".");


  Serial.println (buf);

}  // end of setup

void loop () {}

Just keep the R,G,B and swap out the indices. Then replace them with a dot.

char* SwapDots(char* buf)
{
    buf[0] = buf[1];
    buf[1] = '.';

    buf[6] = buf[7];
    buf[7] = '.';

    buf[12] = buf[13];
    buf[13] = '.';
    return buf;
}

void setup() {
  // put your setup code here, to run once:
    char buf[100] = "R0393 G0432 B1014";
    Serial.println(SwapDots(buf));
}

Thanks that’s perfect!

Thanks so much for the help!!

Turns out im an idiot and was using the a dump from a terminal to determine the proper string.
I was off.

This is the incoming string V0417 R0393 G0432 B1014
and this is what I need to turn it into V0.417 R0.393 G0.432 B1.014.

I am trying to use the code you sent to do that but its replacing instead of adding.
Any tips?

Thanks again!

Do you still need the letters in the final buffer? The method I provided tried to not shifting the buffer because it is complicated.

If you still want the letters. Replace it with itself and a space:

ms.GlobalReplace ("R", "R ");

Then use the SwapDots() to swap and replace the space with a dot. Note that you have to change the indices.

Thanks so much for the tip! I think I got it working.