Category : re

I have a code portion where i imported re library. Here is my code: import re def clean_text(txt): txt = txt.lower() txt = re.sub(r"i’m", "i am", txt) txt = re.sub(r"he’s", "he is", txt) txt = re.sub(r"she’s", "she is", txt) txt = re.sub(r"that’s", "that is", txt) txt = re.sub(r"[^ws]", "", txt) return txt I need a ..

Read more

I just to find all the words in a sentence. I tried the below, but doesn’t work. Thanks import re string1= "This is a nice day – 23 Sep 2019 Oct2021" word1=re.findall(‘b[a-zA-Z]+b’, string1, flags=0) word2=re.findall(‘^[a-zA-Z]+$’, string1, flags=0) word3=re.findall(‘w+’, string1, flags=0) print(word1) –> [] print(word2) –> [] print(word3) –> [‘This’, ‘is’, ‘a’, ‘nice’, ‘day’, ’23’, ‘Sep’, ..

Read more

string = "BANANA" user2= input(f" FARAZ IT’S YOUR TURN : ") vowels = "AEIOU" points=0 if user2[0]== vowels[0]: Faraz_Points= points + len(re.findall(‘(?=ANA)’, string)) print(f’ Faraz scored: {Faraz_Points} points’) I want to it take the word "ANA" from input that is user2 Source: Python..

Read more

I would like to replace %2 by + in my string. I try to use re.sub but I didn’t find a solution. Input: import re; import urllib input_file = re.sub("%20{2}", ‘+’, urllib.parse.quote("Charts Instrument’s Rating+Movment")) input_file Outpout : Charts+Instrument%27s+Rating+Movment Do you have an idea ? Source: Python..

Read more