How to search and lossless replace strings using sed?

Hello,

I would like to replace all occurencies of long data types by others (coresponding int) using 'sed' in the extensive source code of a software package written for 32 bit CPUs.
I must use regular expressions to avoid wrong replacements like

s/unsigned[[:blank:]]+long[^_1-9A-Za-z]/ulong/g

Leaving out the regular expression suffix will also replace variable names starting with 'int' and/or 'long'.

The problem with this is that the detected suffix "[^_1-9A-Za-z]" is also replaced (by an empty string), which destroys the source code.

Is it possible to append/use the detected suffix lossless again using 'sed'?

Thanks in advance,
Michael

Welcome to the forum.

That is a brilliant application for a "back reference". man regex :

,

Try

s/unsigned[[:blank:]]+long([^_1-9A-Za-z])/ulong\1/g

Your original code seems to use EREs (extended regexes). Should that be wrong, escape the parantheses.

it's hard to imagine that after "unsigned long" there is no whitespace