This question already has answers here:
Extract email sub-strings from large document
(14 answers)
Closed 3 years ago.
Do you guys know how I'll be able to extract an email from a string using find()
info = "message email#gmail.com"
I want to be able to get the entire "email#gmail.com" and output only that to the screen.
You can do this by using regex:
import re
emails_list = re.findall('\S+#\S+', info)
Related
This question already has answers here:
Retrieving parameters from a URL
(20 answers)
Closed 3 years ago.
URL example = 'https://stackoverflow.com/questions/ask?newreg=12f6529a5b3449c3be1d14458a4657ef'
i want to return the barcode number after ''newreg' in the URL. The string is not same len everytime
Would appreciate any help here
Thanks
Why not just use simple split() ?
url = 'https://stackoverflow.com/questions/ask?newreg=12f6529a5b3449c3be1d14458a4657ef'
barcode = url.split('=')[-1]
Hope this helps!
This question already has answers here:
Extract email sub-strings from large document
(14 answers)
Closed 4 years ago.
Hi I'm trying to find a list of e-mails from a website. there is 4 e-mail addresses on the website but only returns 2 emails.
I'm using this to help search for the emails.
emails = re.findall(r'[^\s#<>]+#[^\s#<>]+\.[^\s#<>]+',s)
print(count, ' email address found : ',item)
count += 1
You can try out this regex :
regex = r"([\w\.-]+)#([\w\.-]+)(\.[\w\.]+)"
The following pattern should match most forms of email addresses:
emails = re.findall(r'^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*#(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$',s)
This question already has answers here:
How can I split and parse a string in Python? [duplicate]
(3 answers)
Closed 5 years ago.
I need to split the string everytime ; shows up.
words = "LightOn;LightOff;LightStatus;LightClientHello;"
Output should be something like this:
LightOn
LightOff
LightStatus
LightClientHello
Simply, everytime it finds ; in a string, it has to split it.
Thank you for help
res = words.split(";")
Refer to this link for more information on split.
This question already has answers here:
What's the u prefix in a Python string?
(5 answers)
Closed 6 years ago.
I am trying to parse the 'Meghan' part from the line:
link = http://python-data.dr-chuck.net/known_by_Meghan.html
...with the following regex:
print re.findall('by_(\S+).html$',link)
I am getting the output:
[u'Meghan']
Why I am getting the 'u'?
It means unicode. Depending on what you'll do with it, you can ignore it for the most part, of you can convert it to ascii by doing .encode('ascii')
This question already has answers here:
Get plain text from QLineEdit
(2 answers)
Closed 7 years ago.
I am using PyQt and want to get string from text field. I found below solution but it returns a QString. I just want to avoid writing extra code to extract string further. Can anyone suggest a simple solution to retrieve text from text field.
text = self.your_plugin_dlg.ui.yourLineEdit.text()
Thanks.
The only way to get the text is converting the QString into a String
text = str(self.your_plugin_dlg.ui.yourLineEdit.text())