Hello!
I am struggling to mask the last 4 digits of my numbers.
| rex field=FIELD_XY mode=sed "s/[0-9#]{3}$/###/g"
With this code I am able to mask the last 4 digits of all kind of numbers in my table to ####. So the numbers looking like : 123456####.
What I cannot do is to apply this masking only those numbers which are 8 digits or more long. Tried several options and played with regex, but it didn't mask it or over masking everything .
Thank you!
Try this run-anywhere example query.
| makeresults | eval FIELD_XY="12345~12345678" | eval FIELD_XY=split(FIELD_XY,"~") | mvexpand FIELD_XY
```Above just creates test data```
| rex field=FIELD_XY mode=sed "s/(\d{4,})[0-9#]{4}$/\1####/g"
The regex looks for a group of a least 4 digits followed by 4 digits or octothorpes. It then retains the group and replaces the remaining four characters with octothorpes.
| makeresults | eval _raw="1234567890 12345678 1234567"
| rex mode=sed max_match=0 "s/([0-9]{4})([0-9]{4})($|[^0-9])/\1XXXX\3/g"
Thank you!
It was almost perfect, except that it failed if the last digit was a #, then it was not masked with XXXX then.
Try this run-anywhere example query.
| makeresults | eval FIELD_XY="12345~12345678" | eval FIELD_XY=split(FIELD_XY,"~") | mvexpand FIELD_XY
```Above just creates test data```
| rex field=FIELD_XY mode=sed "s/(\d{4,})[0-9#]{4}$/\1####/g"
The regex looks for a group of a least 4 digits followed by 4 digits or octothorpes. It then retains the group and replaces the remaining four characters with octothorpes.
Thank you!
This was the solution what I was looking for 🙂