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 7 years ago.
Improve this question
How can I catch some string like these with a regex in python?
M1Sxs-2839
McS-28S9213
Both the first and the second part (divided by the -) can contains letters and numbers (case insensitive).
You may try the below re.match function.
re.match(r"(?i)[A-Z0-9]+-[A-Z0-9]+$", st)
(?i) helps to do case-insensitive match. Since re.match scans the input from start, you don't need to add start of the line anchor ^ explicitly.
Related
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 10 months ago.
Improve this question
How can I separate data types in a string or list so they can be set to another character, I assume there is something I have missed but everything i have tried so far has now worked for me. so far have tried so split into list and use a for loop to find every int but I can't find a way to differentiate the data types so it can change every int.
You can use regex :
import re
re.sub("\d", "_", "10 4 2")
\d matches any decimal digit character.
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)]
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.
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
The string i needed to format is,
string = "How are you? abcdef"
I need to remove the "abcdef" from the string.
string = string.split(' ')[0]
Edit: Explanation. The line of code above will split the single string into a list of strings wherever there is a double space. It is important to note that whatever is split upon, will be removed. [0] then retrieves the first element in this newly formed list.
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
Is it possible to remove periods from the middle of a string (sentence), leaving the ending period?
The answers that I have seen, basically strip all of the periods.
Remove periods at the end of sentences in python
If I understand correctly, this should do what you want:
import re
string = 'You can. use this to .remove .extra dots.'
string = re.sub('\.(?!$)', '', string)
It uses regex to replace all dots, except if the dot is at the end of the string. (?!$) is a negative lookahead, so the regex looks for any dot not directly followed by $ (end of line).