I have to replace all the numbers in the ranges 35-79 and 235-249 with a text, let's say "hello world".
After a few minutes I came up with this expression:
sed -r "s/((3[5-9]|[4-7][0-9])|(23[5-9]|24[0-9]))/[\1 hello world]/g" file1.txt > file2.txt
The problem I had is that it also identified parts of larger numbers as valid numbers. For example, in the number 256, 56 was detected as a valid input, and that's not what I wanted. These numbers are preceded and followed by white spaces or random alphanumeric characters, so using the word boundary would not be an option. I managed to solve that using negative lookbehind and negative lookahead, obtaining this result:
sed -r "s/(((?<![0-9])3[5-9](?![0-9])|(?<![0-9])[4-7][0-9](?![0-9]))|(23[5-9]|24[0-9]))/[\1 hello world]/g" file1.txt > file2.txt
Unfortunately, sed doesn't recognize lookbehind and lookahead. I know Perl does, but I'm forced to do this using only sed. Any idea about how to solve this in sed?