Only print the date in a string [closed] - python

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 5 months ago.
Improve this question
This is my string
word = " Saturday Fortune 08-09-2022 (4872) Draw Numbers "
But I only want to print the date in the string like this
'08-09-2022'
So how can I achieve this?

Should use a regular expression to find that part in the string. Something like:
import re
match = re.search(r'\d{2}-\d{2}-\d{4}', word)
This already seems to be answered as a subproblem in this thread.

Related

HOW TO REMOVE DUPLICATES IN A ROW IN PYTHON [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
Hi I need to remove the duplicates in python but only when they are in a row. For example:
Input: AAABBCCDDAA
Output:ABCDA
Could you please help me? thnks.
To learn more about text processing in Python3 I recommend training on codingame.com.
def removeDuplicates(inp):
output =""
lastCharacter=""
for character in inp:
output+=character*(character!=lastCharacter)
lastCharacter=character
return output
inpTest ="AAABBCCDDAA"
print(removeDuplicates(inpTest))
ABCDA

Problem in filter column in dataframe by contain function in str by "|" operator [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
Why is not filter the df like in the screenshot
Show the function of str.contain("|") that's didn't work
You need to set the regex parameter of contains to False. In your code now, the string "|" is parsed as a regular expression, but you want to match the literal pipe character.
movies_with_more_dir = movies_df[movies_df['director'].str.contains("|", regex=False)]

Grab specific text from string in Python [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 2 years ago.
Improve this question
How can I grab the invite code from this string?
{awarded:1,inviteURL:https:\/\/www.example.com\/refer\/invite\/111A111A\/}
The expected output would be "111A111A".
Any help is appreciated
I tried it in a simple way, You could give more details for further improvement.
s = "{awarded:1,inviteURL:https:\/\/www.example.com\/refer\/invite\/111A111A\/}"
print(s[-11: -3])
This will do it with ReGex
import re
def findInvite(s):
return re.search(r"(?<=/invite\\/).*(?=\\/)",s).group()
assert findInvite("{awarded:1,inviteURL:https:\/\/www.example.com\/refer\/invite\/111A111A\/}") == "111A111A"
And if this isn't a string but a dict, then change the function to:
def findInvite(d):
s = d["inviteURL"]
return re.search(r"(?<=/invite\\/).*(?=\\/)",s).group()

How to using the "for" loop in python make the output print in one line [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
I have a simple bit of code what using the loop "for" prints out all the leters from input. It looks something like this:
word = str(input('Word here:'))
for i in range(0, len(word), 1):
print(word[i])
I would really like sme help
You can end keyword in print statement to remove the newline character.
print(word[i],end=" ")

Extract Data Enclosed between three asterisks in python [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
I want the data enclosed between three asterisks.And the Word should start with description.
For eg:I have data like
description ***tCore-DFON_P.17-18>dPLUC80115_S19P1>>><<<dPDCL80121_S17P1<100G.IPT.NTTA.SEA.ASE+PC1.LUC/PLD-SEA/PLD_100GEL064.263568***;
I want only
tCore-DFON_P.17-18>dPLUC80115_S19P1>>><<<dPDCL80121_S17P1<100G.IPT.NTTA.SEA.ASE+PC1.LUC/PLD-SEA/PLD_100GEL064.263568
You may use re.findall here:
inp = "description ***tCore-DFON_P.17-18>dPLUC80115_S19P1>>><<<dPDCL80121_S17P1<100G.IPT.NTTA.SEA.ASE+PC1.LUC/PLD-SEA/PLD_100GEL064.263568***;"
matches = re.findall(r'\bdescription\s+\*{3}(.*?)\*{3}', inp, flags=re.DOTALL)
print(matches)
This prints:
['tCore-DFON_P.17-18>dPLUC80115_S19P1>>><<<dPDCL80121_S17P1<100G.IPT.NTTA.SEA.ASE+PC1.LUC/PLD-SEA/PLD_100GEL064.263568']
Note that I use dot all mode in the regex, in case your expected matches might span across more than one line.

Categories

Resources