This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
If I have a string like test string. something \n else how would I split the string on both . and \n characters? I have tried using re.split(". \n", text) but it doesn't seem to be working.
Figured it out - I needed to use re.split("\\.|\n", text).
Related
This question already has answers here:
Regex to find and replace emoji names within colons
(4 answers)
Closed 3 months ago.
At a complete loss here - trying to match a a colon either side of any given word in a passage of text.
For example:
:wave: Hello guys! :partyface: another huge win for us all to celebrate!
An appropriate regex that would match:
:wave:
:partyface:
Really appreciate your help!
\w*:\b
To catch all the content
:[^:]*:
To catch the content between
(?<=:)[^:]*(?=:)
This question already has answers here:
Replacing instances of a character in a string
(17 answers)
Closed 7 months ago.
I am requesting an API which sometimes gives a string that contain "*" characters.
I have to post the output on discord, where ** makes the text bold.
I want to see if a string contains any * and if so put a markdown \ escape character in front of the *.
How can I accomplish this?
As #Random Davis rightly pointed out in the comments, you can use str.replace("*","\*")and it will replace all the * occurrence.
This question already has answers here:
Python string literals - including single quote as well as double quotes in string
(3 answers)
Using quotation marks inside quotation marks
(12 answers)
Closed 3 years ago.
I'm having trouble figuring out how to print a very specific line.
I tried using .format and I also tried the print("str",variable,"str") method but I can't seem to figure out how to make it print correctly.
feet=5
inches=6
print('Room Length:{}' {}"'.format(feet,inches))
I want the computer to print; Room Length: 5' 6"
but I am not sure how to print this while keeping the apostrophe and the quotations for feet and inches.
print('Room Length:{}\' {}\"'.format(feet,inches))
This question already has answers here:
Python string.strip stripping too many characters [duplicate]
(3 answers)
Closed 5 years ago.
lstrip removed additional character, please help me understand it why. Is it removing all the input characters from the beginning?
'http://twitter.com/c_renwick'.lstrip('http://twitter.com/')
>>>'_renwick'
lstrip takes a list of characters to remove from the string. As c is in the list you provided, it gets removed
To achieve what you actually want, use replace:
'http://twitter.com/c_renwick'.replace('http://twitter.com/','')
This question already has answers here:
Python regex -- extraneous matchings
(5 answers)
Closed 6 years ago.
I searched in all the internet and didnt get a good answer on this thing.
What parentheses in python are stand for? its very wierd..
For example, if i do:
re.split(r'(/s*)', "ho from there")
its will give me a list of separate words with the spaces between that... how does its happening?
This isn't specific to python, but in regex those denote a capture group.
Further information on how these are handled in re.split can be seen here