I have a situation..
Having a string which can contain numbers,letters, and some symbols, I want to make an extraction from it or to make some replacements based on some “rules”.
I thing the best is to give some examples of possible situations and what I want to do (display):
String Display1 or Display2
AB_X345 X345 or ###X345
AB_1234 1234 or ###1234
X987_TEXT_4567 X9874567 or X987######4567
X987TEXT4567 X9874567 or X987####4567
X798TEXT X798 or X798####
789TEXT 789 or 789####
X400 X400 or X400
So practically when I find an X followed by numbers I want to display them. If some text appear, I don’t want it displayed or I want it masked with a character(#).
In case no X is present, I want to display only the numbers.
Is Regex the easyest way of doing this? (I am not familiar with regex-just had a bird’s eye view on it).
Can all the rules be gathered in a single regex expression or is to complicated?
Thank you for any sugestions
That’s easy:
Change the last line to
to mask the characters with
#instead of removing them.