1

I've been trying to figure out how to specifically mask certain parts of the string.

For example, if I were to mask first four letters in an email:

[email protected] => ****[email protected]

and

mask four numbers before the last four numbers of a phone number:

+15123452345 => +151****2345

What would each of these regex expressions be using replace?

1 Answer 1

1

For the first one, just match the start of the string and 4 more .:

^.{4}

For the second one, use this:

.{4}(?=.{4}$)

This matches 4 . until it sees that after it, there are 4 more . followed by the end of string.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you tell how can replace all matching with X
You should do some research about the regex API of your language first. @Anuragpareek it will tell you how to do replacements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.