Validate an email in Python/Django [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 days ago.
Improve this question
I'm receiving an email from a http request and I need to validate it. The email filed should have the format: "example#domain.com". The email nmame con contain special characters like [~, !, #, $, %, ^, &, *, _], but may not contain [#, (, ), .]. The email domain and subdomain should not contain special characters.
I'm trying to solve this with regular expressions but I don't have so much experience with this topic.

import re
req = r'\b[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
if(re.fullmatch(req, email)):
#validemail
else:
#invalidemail

Related

Python: how to extract the variables between 2 constant substring [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am trying to extract the variables between 2 constant substring in a string. For example,
I wish to extract the variable Apple, Orange, Watermelon, Kiwi....13cups, 14cups...19cups. I am using the re expression to get to the first step of taking the variable between $ sign but I do not get anything results.
Anyone can advise on the correct expression or if there is a better way to extract it ?
Thanks.
import re
file = '$n$n$n$xa0$n$nSHOWALL$nSHOWALL%GROWTH$n$n$xa0$n$xa0$n$n$n$nApple$na$nOrange$n$nWatermelon$nKiwi$n$nBanana$nJackfruit$n$nGuava$na$nGrape$n$nPlum$na$nOrange$n$nCoconut$nWatermelon$n$n12cups$n13cups$n$n14cups$na$n15cups$n$n16cups$na$n17cups$n$n18cups$n19cups$n'
found = re.findall(r'(?=$(.*?)$)',file)
print(found)
Given that the rule(s) for identifying the required character sequences is ambiguous, I contend that RE is impractical. No doubt it could be done but here's a quick'n'dirty approach to the problem:-
data = '$n$n$n$xa0$n$nSHOWALL$nSHOWALL%GROWTH$n$n$xa0$n$xa0$n$n$n$nApple$na$nOrange$n$nWatermelon$nKiwi$n$nBanana$nJackfruit$n$nGuava$na$nGrape$n$nPlum$na$nOrange$n$nCoconut$nWatermelon$n$n12cups$n13cups$n$n14cups$na$n15cups$n$n16cups$na$n17cups$n$n18cups$n19cups$n'
for token in data.split('$n'):
if token not in ('SHOWALL%GROWTH', 'SHOWALL', '$xa0', 'a', ''):
print(token)

negative lookbehind not working as expected [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have strings of this form:
FPLBX(2x3)ZE(53x13)(4x7)ZGQO
I want to find the blocks in parenthesis but only when they're not preceded by another group.
The other way around works perfectly fine but I can't make it work with preceding.
current regex:
(\(\d*x\d*\))(?<!\))
You simply need to put the so-called negative lookbehind assertion, i.e. the (?<!\))-part, in front of your search re:
>>> import re
>>> txt = "FPLBX(2x3)ZE(53x13)(4x7)ZGQO"
>>> re.findall(r"(?<!\))(\(\d*x\d*\))", txt)
['(2x3)', '(53x13)']

I want to make \ into a string [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 2 years ago.
Improve this question
Edit= Some moderators recommended me to make my self more clear, so here we go.
As a personal project in python, I'm making a very simple software that asks the user for an email address and then checks if the syntaxis of the email is correct.
I made a tuple of special characters that are not allowed in an email address, one of those characters is "\". I was looking online like crazy for how to make \ into a str with no result. I try looking online for the use of the function \ with no result either.
V = "\" doesn't work, it gives me a syntax error. I know it is possible to make it into a string because I've done it with an Input() command.
Please help.
It's not clear to me what language you're using - but in most cases you need to escape the backslash, as it is an escape character itself.
V="\\"
This functionality exists that you can include special characters (in this case, a double quote) in the string:
V="The following will be in quotes: \"Hello, World\""
In this case, the escaped double quotes will be treated as literal characters in the string, and will not signal the end of the string as they would without the escape character.

unable to match regex pattern in python [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am trying to match a regex from an email. If the e-mail says "need update on SRT1000" the regex needs to match. I have my code as below, but it is not working. Can someone look at this and let me know what is wrong here?
def status_update_regex(email):
email = email.lower()
need_sr_update_regex = re.compile('(looking|want|need|seek|seeking|request|requesting)([^/./!/?/,/"]{0,10})(status|update)(^.{0,6})(^srt[0-9]{4})')
if need_sr_update_regex.search(email) != None:
return 1
else:
return 0
You didn't put whitespace \s between words.
You don't have the on string
(looking|want|need|seek|seeking|request|requesting)([\s^.!?,"]{0,10})(status|update)([\s^.]{0,6})(on)([\s^.]{0,6})(srt[0-9]{4})
The best tip I can give to anyone attempting regex matching is to test their solution using https://rubular.com/
Don't put the ^ in the groups, it's trying to match the beginning. Also the extra / are unnecessary.
'(looking|want|need|seek|seeking|request|requesting)([^/.!?,"]{0,10}(status|update)(.{0,6})(srt[0-9]{4})'

How to extract groups contains desired string from between quotes using regex? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I would like to extract some strings from between quotes using regular expression. The text is shown below:
CCKeyUpDomReady('test.asmx/asdasd', 'QMlPJZTOH09XOPCcbB2jcg==', '0OO6h+G2Tzhr5XWj1Upg0A==', '0OO6h+G2Tzhr5XWj1Upg0A==', '/qqwweq2.asmx/qqq')
Expected result must be:
test.asmx/asdasd
/qqwweq2.asmx/qqq
How can I do it? Here is the platform for testing:
https://regexr.com/3n142
The criteria: string which is between quotes must contains "asmx" word. The text is much more than showed above. You can think like that you are searching asmx urls in a website source code.
See regex in use here
'((?:[^'\\]|\\.)*asmx(?:[^'\\]|\\.)*)'
' Match this literally
((?:[^'\\]|\\.)*asmx(?:[^'\\]|\\.)*) Capture the following into capture group 1
(?:[^'\\]|\\.)* This is a beautiful trick gathered from PhiLho's answer to Regex for quoted string with escaping quotes. It matches escaped ' or any other character.
asmx The OP's search string/criterion
(?:[^'\\]|\\.)* This again
' Match this literally
The result is in capture group:
test.asmx/asdasd
/qqwweq2.asmx/qqq

Categories

Resources