extract email address from Notepad++ using regex - regex

I am trying to extract email addresses from notepad++ using RegEx.
I tried like this
Find and Replace
Find: (\b[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b)
Replace : .\1
I am loosing email address instead of text. I need remove all text and keep only email addresses in the file. How to do that?
Abilash Perumandla
hi Gunpreet, kindly share your thoughts to Abi#TEKperfekt.com
Pratap Aneel
15d
Pratap Aneel
please share your thoughts to Pratap.kumar#rsrit.com
naveen kumar
15d
naveen kumar

You need to match and capture the email with a (...) subpattern (so, you do that right), but you need to just match everything else (and that part is missing).
Use
Find what: (\b[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b)|.
Replace with: $1
Then, you might want to use Edit -> Blank Operations -> Remove Unnecessary Blank and EOL menu option.

Related

Get an exact regex match of an email value from a list of email addresses

I have a text field which stores a list of email addresses e.g: x#demo.com; a.x#demo.com. I have another text field which stores the exact value matched from the list of emails i.e. if /x#demo.com/i is in x#demo.com;a.x#demo.com then it should return x#demo.com.
The issue I am having is that if I have /a.x#demo.com/i, I will get x#demo.com instead of a.x#demo.com
I know of the regex expression /^x#demo.com$/i, but this means I can only have one email in my list of email addresses which won't help.
I have tried a couple of other regex expressions with no luck.
Any ideas on how I can achieve this?
You can use this slightly changed regex:
/(^|;)x#demo.com($|;)/i
It will match from either beginning of string or start after a semi colon and end either at end of string or at a semi colon.
Edit:
Small change, this uses look behind and look forward, then you will only get the match, you want:
(?<=^|;)x#demo.com(?=$|;)
Edit2:
To allow Spaces around the semi colon and at start and end, use this (#-quoted):
#"(?<=^\s*|;\s*)x#demo.com(?=\s*$|\s*;)"
or use double escaping:
"(?<=^\\s*|;\\s*)x#demo.com(?=\\s*$|\\s*;)"

how to remove all website addresses in bulk using regex

I have a lot of sites and I want to delete all of the web site address.
example:
http://www.website1.com/product.php?id=
http://www.website2.net/list.php?cid=
http://www.website3.org/view.php?page=
once removed:
product.php? id =
list.php? cid =
view.php? page =
I want to remove them in bulk using regex101 or regex on notepad ++
I want to ask what the code regullar expression to remove all of it?
I find PHP Live Regex easier to use for that purpose since you see the replace results directly (choose preg_replace instead of preg_match):
You can use this regex and choose replace and only keep the first capturing group $1:
(?:[a-z]{4,5}://[a-z.0-9]*\/)?([a-z.\?_=]*)([0-9]*)
Result:
product.php?id=
list.php?cid=
view.php?page=
See: http://www.phpliveregex.com/p/g5q
Use the following regex to search in Notepad++:
.*\/ demo
Then use a space to replace.
Basically we are searching for the last / and removing everything from beginning to that position.

Regex specific Param from Uri

Simply put, I pull the href prop of a link and need to replace it with new link when clicked. The new link needs 1 parameter from the original link (a claim link opening a new window and claiming a task for a user).
Thus far I have a working solution. What I'm wanting is for someone to maybe help me refine my RegEx a little.
For links like:
/crm/v2/claimTask?email=example#gmail.com&id=1372365392-1UsIvb-0002qr-Sz
I use:
$(this).prop("href").match(/(email|order|phone|num)=\s*?(.+)&/)[0].replace(/&/, '')
And get:
email=example#gmail.com
What i'd like to do is be able to remove .replace(/&/, '') and have the regex stop at the & symbol to begin with, but i'm unsure how to do this. Any ideas?
Further examples:
/crm/v2/claimTask?order=123456&id=137236456452-1UweRRwvb-00456jr-Sz
/crm/v2/claimTask?phone=6665554444&id=175655392-4WERTe4-097qt-Da
/crm/v2/claimTask?num=6665554444&id=1372234392-9sfaWa-12374ip-eW
/crm/v2/claimTask?email=email#test.net&id=133453465392-k0wS24S-36735qr-rt
Using:
$(this).prop("href").match(/(email|order|phone|num)=\s*?(.+)&/)
Would yield:
order=123456&
phone=6665554444&
num=6665554444&
email=email#test.net&
Try this:
$(this).prop("href").match(/((email|order|phone|num)=\s*?(.+))&/)[1] //"email=email#test.net"
$(this).prop("href").match(/((email|order|phone|num)=\s*?(.+))&/)[3] //"email#test.net"
The above just puts the part without the & into a capture group. You could also use a positive lookahead:
$(this).prop("href").match(/(email|order|phone|num)=\s*?(.+)(?=&)/) //["email=email#test.net", "email", "email#test.net"]
Just use a lookahead:
(email|order|phone|num)=\s*?(.+)(?=&)
It will not "eat" the ampersand.

Regex email(several types) extraction

I'm tring to extract email adressess from a content. I've a problem about false positives.
My regex for: example#site.com
[^\.^\w+](\w+) *?# *?(\w+) *?(?:\.|dot) *?(\w+)
Regex for: example#sub.site.com
[^\.^\w+](\w+) *?# *?(\w+) *?(?:\.|dot) *?(\w+) *?(?:\.|dot) *?(\w+)
I want the first regex not to match with:
example#sub.site
How can I fix it?
The only way to distinguish example#site.com and example#sub.site is to maintain a list of valid top level domains (yes, I'm sorry).
i.e, replacing your last (\w+) by (com|org|info|ly|... and so on.
There is no universal way.
Also, you could do only one regex.
Also, my address could be example#sub1.sub2.site.com, be careful...

Need help with regex Email in Notepad++

I have a list with contacts each line, we have to replace the whole line in to single email:
Name, Surname, Address, Email, Phone
=>
Email
I know how to find email, but I need smth like find and replace to "" everything but Email
This worked for me using Notepad++ to remove everything except for the email addresses:
Ctrl + H to bring up Find/Replace dialog box.
Change to the the Replace tab.
Find what: ^.*(\<[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Za-z][A-Za-z][A-Za-z]?[A-Za-z]?\>).*$
Replace with: \1
You need to select [Regular Expression] at the bottom of the Find/Replace dialog box.
Then click [Replace All]
Assuming your email regular expression is well-written and won't match anything that isn't an email...
Find (() characters are significant):
^.*(your email regex here).*$
Replace with:
\1
I don't think you can replace "everything except" any regex in notepad++. I usually use macros for such a problem.
But another method would it be, to import the data into Excel as a CSV, mark the column with the email adresses and copy-paste them to notepad++. That's another trick I usually do.