how would i match get a word only if it is between 2 numbers using regex

how would I match get a word only if it is between 2 numbers using regex
eg the input is: 5testword5,5testword5testword43 it matches testword;(so I can replace testword with something else)
but 5testword shouldn't match
and neither should testword5 match;
how would I do that?

(edited it to make it more understandable and added more examples)
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>
#include <regex>
using namespace std;

int main()
{
    string line{"123hello456"};
    regex re{"(\\d+)\\D+(\\d+)"};
    line = regex_replace(line, re, "$1XXX$2");
    cout << line << '\n';
}

@dizzyDon
only works for the first word, inputs such as 123hello123hello123
won't work.
Topic archived. No new replies allowed.