How do I change two letters closest to a string and one letter immediately after a string using Notepad++?
I have a list of emails, and I want to change the two letters before "@" and the first letter after "@" using Notepad++.
For example:
[email protected]
becomes
userna**@*ourdomain.com
Solution 1:
I want to change the two letters before "@" and the first letter after "@"
Menu "Search" > "Replace" (or Ctrl + H)
Set "Find what" to
..@.
Set "Replace with" to
**@*
Enable "Regular expression"
-
Click "Replace All"
Before:
[email protected]
After:
userna**@*ourdomain.com
Further reading
- How to use regular expressions in Notepad++ (tutorial)
- Notepad++: A guide to using regular expressions and extended search mode
- Regular Expressions Tutorial
- RegExr: Learn, Build, & Test RegEx
- regex101: Online regex tester and debugger
- RegExper: Regular Expression Visualiser
Solution 2:
You can do this by using a regex search/replace.
At the bottom, select Regular Expression.
In the Search for entry, you type in: ..@.
In the Replace with, you type in **@*
Then press the button Replace All
This works because Regex searches will only replace if its search criteria matches exactly. The match is explained as follows:
..@.
There are 3 dots and an @
:
-
@
has no special meaning in regex so it means a literal @. -
.
means any character, exactly once. By writing..
it means 2 characters of any kind, as long as there are 2 characters.