Hi, @Jesper-Bødewadt-Møller,
I would use this strategy :
If we find some digits, right after the syntax %X, just rewrite this NON wanted block, as it !
If we find other 3 digits elsewhere ( which are good candidates ), replace each one with a 4 digit
This simple way avoid us to verify where a 3 digit is found ( inside a %X... block or elsewhere :-))
So, open the Replace dialog ( Ctrl + H )
SEARCH (?-i)%X\d+|(3)
REPLACE ?{1}4:$0
OPTIONS Wrap around and Regular expression ticked
ACTION Click on the Replace All button
For instance, assuming the initial text below :
abc3.%X31 def abc3%X11223def abc3%X773777.3def abc3%X31 333def abc3% X321 333def abc3%X 321 333def abc333.%X333333.333def
It would be changed into :
abc4.%X31 def abc4%X11223def abc4%X773777.4def abc4%X31 444def abc4% X421 444def abc4%X 421 444def abc444.%X333333.444def
Remark :
Just note that the 3 digits are replaced by a 4 digit , in the parts % X321 and %X 321, as they are not exactly of the form %Xdigitdigit…digit !!
Notes :
The modifier (?-i) forces the search to be NON-insensitive to case ( so sensitive ! )
Then the regex engine looks for, either :
The exact string %X, followed by, at least, one digit ( %X\d+ )
Any digit 3, stored as group 1, because of the surrounding parentheses ( (3) )
In replacement :
If group 1 exists ( second alternative ), we replace with a single 4 digit ( part before the colon )
ELSE, we just rewrite the entire matched string %X##### ( regex $0 , after the colon )
Best Regards,
guy038