@Giambattista-Benacchio said:
Saluti e molte grazie per la collaborazione
I thank you, and also commend you for finding an improvement on my solution. I might have to borrow that idea for any future requests.
In step#1 you say the occurrence MUST be at the beginning of the line. Not necessary if you know how to search for text within a line. In normal search mode just type the occurence to search for, it can be anywhere in the line. In regular expression mode the same can be true, however you can also be more selective using other search patterns to exclude some possibilities if required.
There are possibly some improvements to your step#4. Instead of \d\d\d\dX you can write this as \d{4}X. This means 4 of a single digit. If however this number could be larger than 4 digits, also consider \d+X which means as MANY digits as possible followed by a X (so 5X, 01X, 2304X, 1234567890123456789X etc). This is the ability available in the regular expression.
Terry