I've have a input string:

> 
> 12345,3244,654,ffgv,87676,988ff,87657
> 
> 
> 

I'm having a difficulty to transform all terms in the string that are not five digit numbers to a constant 34567 using regular expressions. So, the output would be like this:

> 
> 12345,34567,34567,34567,87676,34567,87657
> 
> 
> 

For this, I looked at two options: 

1. **negated character class**: Not useful because it does not execute directly on this expression `,[^\d{5}],`
2. **lookahead and lookbehind**: Issue here is that it doesn't include non-matched part in the result of this expression `,(?!\d{5})` or `(?<!\d{5}),` for the purpose of substitution/replace.

Once the desired expression is found, it would give a result so that one can replace non-matched part using tagged regions like `\1`, `\2`.

Is there any mechanism in regular expression tools to achieve the output as mentioned in the above example?

Edit: I really appreciate those who have answered non-regex solutions, but I would be more thankful if you provide a regex-based solution.