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 2 years ago.
Improve this question
I am having a sentence as below
Eg:
Original Strings can be in below formats.
"[PartnerID:2012345][Failure] Caused by :This is the Failure Name"
"[Failure] caused by This is the failure name"
"Reliability: oscrash in This is the failure name"
I want the string to be trimmed to This is the Failure Name.
Can anyone please help me in writing code for this in python?
Sorry, I had left out other sentences before
Let:
str1 = "[PartnerID:2012345][Failure] Caused by :This is the Failure Name"
To get what you require, we split:
res = str1.split(":")[-1]
if it is like:
str1 = "[PartnerID:2012345][Failure] Caused by This is the Failure Name"
then you can:
res = str1.split("Caused by ")[-1]
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
there's a form (pyqt5), i take date from it:
def buttonclicked(self):
since = self.Since.text()
Then I put that since here:
result, data = mail.search(None, '(SINCE {since} )'.format(since=since))
Error is :
b'[CANNOT] Unsupported search criterion: SINCE 10-09-2019 '
The date needs to match the following format:
imap.search(None, '(SINCE 10-Sep-2019)')
SEARCH BEFORE/AFTER with Pythons imaplib
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 3 years ago.
Improve this question
1 - Supr Senior: M66tzer, Bill)
first_name= Bilr '(' as first name = Roger and last name= Dell..for any string it shuld read till ( and split the name as first name and last name how to write regex
It should support all the above cases
The below code does. It doesn't use split(), but search() and capturing parentheses.
for case in ''' Pocatello, ID/ (Habashi, Yashar)
Idaho Falls, ID/ (Pigott, Joseph)
orian flex joy, Lex/ (Bannet, Joseph)'''.split('\n'):
l_name, f_name = re.search(r'\((.*), (.*)\)', case).group(1, 2)
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 3 years ago.
Improve this question
I am trying to separate all the images from the following string.
how can I get a list of images that start with "comp1/img_" and are either split by a "," or a ";"
/*jsonp*/jsonresp({"img_set":"comp1/img_23434;comp1/img_3243r43r,comp1/img_o43nfjr;comp1/img_wjfno43,comp1/img_nrejfner;comp1/img_jrenckerjv,comp1/img_23434k;comp1/img_rkfnk4n"},"fknreff\",");
so I would end up with a list like...
comp1/img_23434
comp1/img_3243r43r
comp1/img_o43nfjr
comp1/img_wjfno43
comp1/img_nrejfner
comp1/img_jrenckerjv
comp1/img_23434k
comp1/img_rkfnk4n
any help would be appreciated.
thanks
You can do this:
>>> data = '/*jsonp*/jsonresp({"img_set":"comp1/img_23434;comp1/img_3243r43r,comp1/img_o43nfjr;comp1/img_wjfno43,comp1/img_nrejfner;comp1/img_jrenckerjv,comp1/img_23434k;comp1/img_rkfnk4n"},"fknreff\",");'
>>> import re
>>> re.findall(r'comp1/img_[^;,"]+', data)
['comp1/img_23434', 'comp1/img_3243r43r', 'comp1/img_o43nfjr', 'comp1/img_wjfno43', 'comp1/img_nrejfner', 'comp1/img_jrenckerjv', 'comp1/img_23434k', 'comp1/img_rkfnk4n']
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 3 years ago.
Improve this question
How to get what I want? For example, I have a string like this
'RC00001 C00003_C00004RC00087 C00756_C01545RC01045 C06756_C03485'
I want to get
'RC00001 C00003_C00004','RC00087 C00756_C01545','RC01045 C06756_C03485'
What should I do? I have tried many times, but I failed. Please help me! Thank you!
answer=[]
a="RC00001 C00003_C00004RC00087 C00756_C01545RC01045 C06756_C03485"
b = a.split("RC")
for i in b[1:]:
answer.append("RC%s" % (i))
print(answer)
This will output:
['RC00001 C00003_C00004', 'RC00087 C00756_C01545', 'RC01045 C06756_C03485']
If you want to achieve this using regex, you could try the following
import re
input_str = 'RC00001 C00003_C00004RC00087 C00756_C01545RC01045 C06756_C03485'
pattern = '(RC[\d+]+\s+C[\d]+_C[\d]+)'
print(re.findall(pattern, input_str))
# output
# [('RC00001 C00003_C00004', 'RC00087 C00756_C01545', 'RC01045 C06756_C03485')]
provided the format is always RC{numbers} C{numbers}
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 6 years ago.
Improve this question
I have a string
<b>Status : Active<br>Code : C1654<br><br>Shop <a class="top"<b>Shop A</b></a></b>
And I want get Active , C1654 and Shop A.
How to do the same thing in Python?
use python re module
(you didn't explain the pattern you wanted to follow so I can just give an example that will work for the above string):
import re
results = []
reg = '.*?>.*?: (.+?)<br'
my_str = '<b>Status : Active<br>Code : C1654<br><br>Shop <a class="top"<b>Shop A</b></a></b>'
results+=re.findall(reg,my_str)
reg2 = '<a.*?<b>(.*?)</b>'
results += re.findall(reg2,my_str)
print result
>>>['Active', 'C1654', 'Shop A']
I hope I helped