Detect partial email pattern in PHP [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am writing an unsubscribe option of email newsletters.
I have to detect emails of following format:
<0 or more alphanumeric letter/digit only>, then one <#> character, then <1 or more alphanumeric letter/digit>, then a <.> character, then <at least 2 alphanumeric letter/digits>
I need "zero" or more alphanumeric character before # character and not "one" or more because sometimes I want to unsubscribe whole domain names, so in that case the pattern to match is #example.com, and I also want to detect full email, it starts with an alphanumeric character.
How can I write the code to detect?
I take the email from url as $_GET['email']
For example url will be:
http://www.example.com/php/unsubscribe.php?email=#example.com
http://www.example.com/php/unsubscribe.php?email=#example.co
http://www.example.com/php/unsubscribe.php?email=abc#example.co

well the Regex then simply reads
/#.+\.[^\.]{2,}$/
EDIT: I used .* and [^\.] even though the OP asked for "alphanumeric letter/digit" - however, valid E-Mail addresses include stuff like dashes, underscores etc... Completely matching ALL valid email adresses is incredibly complex! (see: http://www.regular-expressions.info/email.html)

You could use the below regex.
[A-Za-z0-9]*#[A-Za-z0-9]+\.[A-Za-z0-9]{2,}
DEMO
[A-Za-z0-9]{2,} matches two or more alphanumeric characters. You could specify the character range inside {} paranthesis.

Related

Why is the Regex for my product's code not working? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm trying to do Regex code for product's code in VSCode's HTML. My product's code has the following conditions:
Required enter 6 characters
First 2 characters must be letter and uppercase
Next 4 characters must be numbers.
I have tried this regular expression and it doesn't work:
^[A-Z]{2}+\[0-9]{4}$
Your regex should be:
^[A-Z]{2}[0-9]{4}$
This corrects the escaping of your character class; that made it no longer a character class but a series of characters to match in the regex, ending with 4 ]s. The + also is not needed as the {2} is stating only 2 uppercase alpha characters are allowed.
You can also swap the [0-9] with \d which is the metacharacter for an integer. With PHP regexs you also need delimiters so something like:
/^[A-Z]{2}\d{4}$/
could be used in preg_match.

PHP - preg_match explanation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Im a beginner in PHP I just want to ask can someone explain to me this line of code.
(preg_match('/^\w{5,}$/', $username))
Thankyou in advance. :) Your answer is so much appreciated. :)
Your PHP match string is
/^\w{5,}$/
and a PHP match string is surrounded by / characters which are not part of the RegEx string itself.
According to the comments your problem is about understanding regular expressions, not PHP.
^ is the beginning of the line, correct
$ is the end of the line, correct
\w Any word character (letter, number, underscore)
a{5,} does mean 5 or more characters 'a'
Therefore: If there are 5 or more any word characters in the username the function returns a positive result.
Or even easier: A username needs to contain at least five any word characters.
Learn more about regular expressions and how they work. Some explanation can be found in this comment.

limiting filter length in regex [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Here I have regex, in which I want it to filter only word length >8 and <15 characters. I added
(?=.{8,14})b$
REGEX-http://regex101.com/r/sA5xL5
but it does not make any diff.
`^(?=.{8,14})b$\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$^|^2(?:0[01378]|3[0189]|4[017]|8[0-46-9]|9[012])\d{7}|1(?:(?:1(?:3[0-48]|[46][0-4]|5[012789]|7[0-49]|8[01349])|21[0-7]|31[0-8]|[459]1\d|61[0-46-9]))\d{6}|1(?:2(?:0[024-9]|2[3-9]|3[3-79]|4[1-689]|[58][02-9]|6[0-4789]|7[013-9]|9\d)|3(?:0\d|[25][02-9]|3[02-579]|[468][0-46-9]|7[1235679]|9[24578])|4(?:0[03-9]|2[02-5789]|[37]\d|4[02-69]|5[0-8]|[69][0-79]|8[0-5789])|5(?:0[1235-9]|2[024-9]|3[0145689]|4[02-9]|5[03-9]|6\d|7[0-35-9]|8[0-468]|9[0-5789])|6(?:0[034689]|2[0-689]|[38][013-9]|4[1-467]|5[0-69]|6[13-9]|7[0-8]|9[0124578])|7(?:0[0246-9]|2\d|3[023678]|4[03-9]|5[0-46-9]|6[013-9]|7[0-35-9]|8[024-9]|9[02-9])|8(?:0[35-9]|2[1-5789]|3[02-578]|4[0-578]|5[124-9]|6[2-69]|7\d|8[02-9]|9[02569])|9(?:0[02-589]|2[02-689]|3[1-5789]|4[2-9]|5[0-579]|6[234789]|7[0124578]|8\d|9[2-57]))\d{6}|1(?:2(?:0(?:46[1-4]|87[2-9])|545[1-79]|76(?:2\d|3[1-8]|6[1-6])|9(?:7(?:2[0-4]|3[2-5])|8(?:2[2-8]|7[0-4789]|8[345])))|3(?:638[2-5]|647[23]|8(?:47[04-9]|64[015789]))|4(?:044[1-7]|20(?:2[23]|8\d)|6(?:0(?:30|5[2-57]|6[1-8]|7[2-8])|140)|8(?:052|87[123]))|5(?:24(?:3[2-79]|6\d)|276\d|6(?:26[06-9]|686))|6(?:06(?:4\d|7[4-79])|295[567]|35[34]\d|47(?:24|61)|59(?:5[08]|6[67]|74)|955[0-4])|7(?:26(?:6[13-9]|7[0-7])|442\d|50(?:2[0-3]|[3-68]2|76))|8(?:27[56]\d|37(?:5[2-5]|8[239])|84(?:3[2-58]))|9(?:0(?:0(?:6[1-8]|85)|52\d)|3583|4(?:66[1-8]|9(?:2[01]|81))|63(?:23|3[1-4])|9561))\d{3}|176888[234678]\d{2}|16977[23]\d{3}|7(?:[1-4]\d\d|5(?:0[0-8]|[13-9]\d|2[0-35-9])|624|7(?:0[1-9]|[1-7]\d|8[02-9]|9[0-689])|8(?:[014-9]\d|[23][0-8])|9(?:[04-9]\d|1[02-9]|2[0-35-9]|3[0-689]))\d{6}|76(?:0[012]|2[356]|4[0134]|5[49]|6[0-369]|77|81|9[39])\d{6}|80(?:0\d{6,7}|8\d{7})|500\d{6}|(?:87[123]|9(?:[01]\d|8[0-3]))\d{7}|8(?:4[2-5]|70)\d{7}|70\d{8}|56\d{8}|(?:3[0347]|55)\d{8}|8(?:001111|45464\d)$|(?:\((\+?\d+)?\)|(\+\d{0,3}))? ?\d{2,3}([-\.]?\d{2,3} ?){3,4}`
please dont bother about regex length.
It matches even if match length exceeds
What is missing to restrain it to filer 8-14 length pattern match only.
First off, ^(?=.{8,14})b$ means "at the beginning of the string as asserted by ^, look ahead to see if we can find a single character between 8 and 14 times, and if yes, then match a single character b then the end of the line $. You cannot have one line that is both a single character b and 8 characters in length. This part of the expression can never match. See demo.
But your regex still finds an overall match. Why? Clearly, even if ^(?=.{8,14})b$ were able to match anything, it does not set a condition for the whole expression, because something later in the regex overrides it: an alternation (|) which means that we can match what's on the left OR what's on the right.

validate Regex in php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How this regex works?
'/[_a-z0-9-]+(\.[_a-z0-9-]+)*\s*#\s*[a-z0-9-]+(\s*\.\s*[a-z0-9-]+)*(\s*\.\s*[a-z]{2,6})/ie'
I got this regex on web, I use cheatsheet but could not understand it.
Considering the # symbol, that looks like validation for email addresses.
Explanation:
The white-space characters are set to +, between zero and unlimited. They are not necessary. What is necessary however is the # symbol and between 2 and 6 characters after a final . This is entirely indicative of an email address.
If I sent an email to some guy #whatever.com, perhaps a typo, I could simply strip the white-space before sending rather than spit out an error.
The addition of allowing white-spaces could also mean this is used for a list of email addresses. Note that with the global modifier, the following would match 4 email addresses with the regular expression:
apple#man.com,
thatguy#something.org,
holy#moly.com,
regex#friends.net

Can anyone decrypt this string using PHP? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Today I came across a job ad where you should decrypt a string that holds valid email address using PHP. So they posted this string, that represents crypted email address, and when you decrypt that email address you can send them email and show that you are Senior PHP developer.
And they posted another email address for Junior developers.
Now this seems to complicated for me so I wont send them email anyway since I already have a job, but I'm wondering is this even possible since you can't have key if using mcrypt functions.
Anyway, this is the string:
MDA3MTY4MDAwODg4MDE0NzIwMDAwMzg4MDAwNDQ0MDAwNTEyMDAwMzg4MDI1NjAwMDA3NDg4MDA3Mjk2MDAzNTUyMDAyOTQ0MDAwODMyMDAzNjQ4IzYzNzIyMzI4NjY1NjM1
Company name is Aduro, and their emails are xxx#aduro.hr, so we are looking for email that ends with #aduro.hr
That string represents valid email address, is anyone good enough to decrypt this?
Not an answer, but some observations:
MDA3MTY4
MDAwODg4
MDE0NzIw
MDAwMzg4
MDAwNDQ0
MDAwNTEy
MDAwMzg4
MDI1NjAw
MDA3NDg4
MDA3Mjk2
MDAzNTUy
MDAyOTQ0
MDAwODMy
MDAzNjQ4
IzYzNzIy
MzI4NjY1
NjM1
Every column containing a digit only contains digits and lowercase letters. Every column containing an upper case letter does not contain any digits.
If it is an e-mail address, then I would tentatively assign IzYzNzIy as the dot character '.' Nothing immediately strikes me as likely to be the '#', possibly the MDI1NjAw because it is the only one starting with MDI. The other non-MDA, MDE0NzIw, is in the correct position for a punctuation character in someone's name: "Smith-Jones" say. That would leave all the MDAs as alphabetic characters. What is happening after the potential dot is anyone's guess. Are there any single letter codes allowed there? NjM1 could be short for <CR><LF>.
Maybe we are looking at four character code elements?
MDA3
MTY4
MDAw
ODg4
MDE0
NzIw
etc.
Why are You thinking of mcrypt? It could be anything. Looks like a base64_encoded string.
Or something else. I think that they just don't want mails from 'senior' developers.

Categories