Searching messages using regex - gmail api - php

I am looking at building a small web application which looks for emails which contain serial keys/codes in an email. I have tried searching around but not sure if Gmail API accepts searching in messages using REGEX.
Anyone got any ideas or used it before?

The Gmail API search has the same features the Gmail client has, which is documented here. It has no support for regex, sadly.

It's better to search with keywords rather regex. Gmail doesnt support regex based search.
Example:- subject:dinner Words in the subject line
Example:- "dinner and movie tonight" Search for an exact word or phrase

Related

Best Choice Regex for extract the Facebook Link

i search the best regex method for the most functionality.
I search on Google and will extract the Facebook Links. Because Google has no Search API that works 1to1 with the exact Google Results i don't can use the API.
I send now a normal request to google, extract the html code and will find all Facebook Link without google parameters.
Examples you find on regex debbuger.
I will see only this links if is possible.
Here Example Strings to search:
`
/url?q=https://www.facebook.com/pageid/about&sa=U&ved=0ahUKEwi27NeDvfTTAhWBfywKHbuDDS4QjBAIHDAB&usg=AFQjCNH7T2JEP5DzGpiiwT_pMt2oGJ10ow
/url?q=https://www.facebook.com/pageid/%3Fpnref%3Dlhc&sa=U&ved=0ahUKEwiWv8S6vfTTAhUEBiwKHW04AH8Q_BcIyQQoATBu&usg=AFQjCNEZIUb1yqqYtzjPfDEVi4GPHDY5FQ
/url?q=https://www.facebook.com/pageid%3Fpnref%3Dlhc&sa=U&ved=0ahUKEwiWv8S6vfTTAhUEBiwKHW04AH8Q_BcIyQQoATBu&usg=AFQjCNEZIUb1yqqYtzjPfDEVi4GPHDY5FQ
/url?q=https://www.facebook.com/name-name-585606818284844/%3Fpnref%3Dlhc&sa=U&ved=0ahUKEwiWv8S6vfTTAhUEBiwKHW04AH8Q_BcIyQQoATBu&usg=AFQjCNEZIUb1yqqYtzjPfDEVi4GPHDY5FQ
/url?q=https://www.facebook.com/name-name-585606818284844%3Fpnref%3Dlhc&sa=U&ved=0ahUKEwiWv8S6vfTTAhUEBiwKHW04AH8Q_BcIyQQoATBu&usg=AFQjCNEZIUb1yqqYtzjPfDEVi4GPHDY5FQ`
Thats my Regex this works but not for all options. Regex Debugger:
https://regex101.com/r/LcYz8c/8
Something like:
"q=(https?://.*?facebook.com/)derName-/"
"q=(https?://.*?facebook.com/)derName(?:%[^%]*%..|[-/])?([^&]‌​+)"
might be what you are looking for. From what I see in your example, it looks like you want:
everything from the http up to the first / after the domain. Then skip the derName, and then grab everything up to the next &. So this is going to use 2 capture groups. Hope that helps!
Try this:
q=(https:\/\/www.facebook.com.*?)&
https://regex101.com/r/LcYz8c/11

Send Text Message From PHP Phone Number

I'm a bit confused here and due to the keywords involved Google has not been much help. I want to send text messages from my website to users with cellphones via SMS. Sounds simple enough using things like 1234567890#carrier.com with php mail scripts right? Well one thing I've encountered before is that sometimes it sends an MMS(multimedia message) instead of a regular text message.
What I am trying to find out(using keywords in Google, send text message phone number php) is how to get a phone number for your website? I've seen sites that actually have a phone number linked to the site that you can receive messages from.
Example Facebook uses 32665 to send and receive messages on.
How do you accomplish this?
Is it any way possible using the 1234567890#carrier.com with php mail to strictly only send a text message and not multimedia?
Example php mail script using a phone number:
<?PHP
mail("5558349324#vtext.com", "", "Test SMS", "From: RRPowered <test#rrpowered.com>rn");
?>
Also thanks to any help ahead of time, because I am really really confused at this point.
UPDATE: I just tried using the regular PHP mail functions to a phone number and it appears to cut the messages off at around 140 characters(I believe that is standard message size).
UPDATE 2: Before anyone mentions API like Text Magic, I am aware of those things, BUT I am wanting to build my own code instead of integrating someone elses API(if possible).

RegEx extract website url from email address w/ sub-sub-domain

We are trying to extract from an email list a valid url for that organization.
abc#charleston.k12.il.us is easy, but sometimes we have
someone#u40gw.effingham.k12.il.us where the 040gw is a subdomain for internal mail.
Another example is someone#mail.meridian223.org or someone#athletics.msstate.edu
What would be the most efficient way to capture the .edu + the preceding name only, without additional subdomains, or in the case of high schools the whole part k12.il.us plus the preceding name only?
Tried so far:
/#(([a-zA-Z0-9]*)([.])([a-zA-Z0-9]*)|#([a-zA-Z0-9]*)([.])([a-zA-Z0-9]*)([.])([a-zA-Z0-9]*)([.])([a-zA-Z0-9]*)([.])([a-zA-Z0-9]*))/
You can try the following regex pattern:
#.*?([^.]+[.]\w{3}|[^.]+[.]k12[.]il[.]us)$
Where, you can replace \w{3} with your list of possible extensions, like org, edu, net etc. An example would be like:
#.*?([^.]+[.](edu|org|net|info|com)|[^.]+[.]k12[.]il[.]us)$
You can see it working on regexr.com

regexp not catching all emails

I am trying to get emails in a php program and I am using the following regexp
([a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*#(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)\b)siU
This appears to be working fine for getting your standard emails. Such as me # gmail.com or you # hotmail.com
Where this fails is on emails with ending such as co.uk. Now I have tried adding co.uk in my regexp as such
([a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*#(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|co.uk|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)\b)siU
But that just gives me the same output as the original regexp. Where the output of the email is, you#co . I also tried just adding in uk. What am I missing on this one? Is it the second period throwing it off?
Ideally I am trying to make it catch all emails with .com .net .org co.uk .au .ca. Basically I am searching for all US, UK, AU and CA emails. Can anyone spot what my mistake is to be able to output non US emails properly like you # yoursite.co.uk instead of you # yoursite.co
Thank you. The spaces in the emails shown for example are only there to get this to post.
Edit: I am not trying to validate the emails, its a series of emails that can be anything that are in an array and I am trying to only catch specific ones for a database. Sorry for not making that clear initially.
Edit2: Here is my working string for my issue. Thanks everyone
^([a-zA-Z0-9_\-\.]+)#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$^
Do NOT use regex to validate email addresses. Use libraries that do it correctly.
See I Knew How To Validate An Email Address Until I Read The RFC for more information.
|co.uk|
try to (not in [] , dot mean anything but break link)
|co\.uk|
You have to escape the dot like this.
co\.uk
If you are trying to match only valid emails this regexp should do the trick
(\s)?(([^\s]+)\#([^\s]+))
What am I missing on this one?
You are adding terms to a non-capturing group. So how can any output based on your regex contain anything in a non-capturing group? Not to mention the mistake in the term you added that nacholibre mentioned.
Dont use regex for email, you wont like it, and you will fail.
filter_var()
http://php.net/manual/en/function.filter-var.php
FILTER_VALIDATE_EMAIL
http://www.php.net/manual/en/filter.filters.validate.php

Regex to retrieve all URLs not containing specific string

I am using the Google Analytics PHP API, and trying to use it to retrieve the most popular links on my website.
It works, but it retrieve some duplicates due to it retrieving URLs containing query strings. So basically, I want to retrieve all the links which do not contain the string "?start=" inside them. I think this can be done via regex (Google Analytics accepts regex filters), but don't know how.
Any ideas?
Thanks!
You can use negative look ahead regex assertion.
See http://www.perlmonks.org/?node_id=518444 and http://www.regular-expressions.info/lookaround.html
your_string(?!\?start=)

Categories