Exclude already masked data in regex
-
hi I am trying to mask 3 to 8 digit numbers alone exclusively, by excluding already masked data with another regex pattern. For example it should not match the masked patterns like [xX\-\*\d{1,4}] , but match the pattern \d{3,8} Can you please help with the regex pattern to achieve this? I have tried something like this, but its not matching for the pattern \d{3,8}
(?<=(?
Input :
1234
x123412345678
-123412345678
*123412345678
123
1234
12345
123456
1234567
12345678Expected masking
****
x1234****
-1234****
*1234****
****
****
****
****
****
**** -
hi I am trying to mask 3 to 8 digit numbers alone exclusively, by excluding already masked data with another regex pattern. For example it should not match the masked patterns like [xX\-\*\d{1,4}] , but match the pattern \d{3,8} Can you please help with the regex pattern to achieve this? I have tried something like this, but its not matching for the pattern \d{3,8}
(?<=(?
Input :
1234
x123412345678
-123412345678
*123412345678
123
1234
12345
123456
1234567
12345678Expected masking
****
x1234****
-1234****
*1234****
****
****
****
****
****
****If I were to use Notepad++ then the find regex would be:
([x\-*]\d{1,4})?(\d{3,8})
So it ties the 1-4 numbers immediately following a x (or X as Notepad++ normally case insensitive), a - (this is a meta character so needs the escape char to make it a normal char) or a *. Having them in a group with a ? allows for non capture if the line doesn't start with the x, - or *. The second group captures between 3 and 8 numbers. Now this all works as expected in Notepad++, however sometimes these don't translate well across the various regular expression engines. As you haven't provided that info I can't give you an answer specific to your need. Also I note you seem to want to "mask" the 3-8 digits. As it stands my 2nd group will just support replacing with a fixed number of "*", so some adjustment would be needed. Hopefully this has helped you though to continue with a final solution. Terry
-
If I were to use Notepad++ then the find regex would be:
([x\-*]\d{1,4})?(\d{3,8})
So it ties the 1-4 numbers immediately following a x (or X as Notepad++ normally case insensitive), a - (this is a meta character so needs the escape char to make it a normal char) or a *. Having them in a group with a ? allows for non capture if the line doesn't start with the x, - or *. The second group captures between 3 and 8 numbers. Now this all works as expected in Notepad++, however sometimes these don't translate well across the various regular expression engines. As you haven't provided that info I can't give you an answer specific to your need. Also I note you seem to want to "mask" the 3-8 digits. As it stands my 2nd group will just support replacing with a fixed number of "*", so some adjustment would be needed. Hopefully this has helped you though to continue with a final solution. Terry
hey Terry, Thanks for the suggestion. I am trying to achieve this patter replacement in java This one I thought of it but it is not working out for the input *1234 x1234 -1234 these kind of inputs should not be masked and output should be as it is *1234 / x1234 / -1234 whatever you have given works fine for *12345678 x12345678 -12345678