0

re.sub(r'a(?=b)','*','The lion and the Fox')

I need to get the inputs and then substitute with * but Im not getting output , like if I give, a=input() b=input() c=input () print(re.sub(r'a(?=b)','*',c)) Instead of the input string, the characters a and b are replaced in 'c'. How to replace the given string with the INPUTS a and b ??

24th May 2020, 5:09 PM
Levi
Levi - avatar
7 Réponses
0
Valmob101 a=aa b=bb c= my string is aa bb , output:: my string is * bb
24th May 2020, 5:45 PM
Levi
Levi - avatar
+ 1
use:( f ".........." ) instead of r , then place variables inside {}. e.g. f "hello{a}"
24th May 2020, 5:23 PM
Lerninn
+ 1
Mndm r stands for raw string which means the string cannot escape character by \(backslash) f stands for format in which we can include identifiers, vars etc. Inside{}. It is a replacement for .format.
24th May 2020, 5:37 PM
Lerninn
0
Valmob101 sorry but I didn't get the output
24th May 2020, 5:42 PM
Levi
Levi - avatar
0
Mndm Please also include the output you want.
24th May 2020, 5:44 PM
Lerninn
0
Mndm solution to yours: Use this pattern instead: re.sub(f'{a} (?={b})','* ',c) To fulfil your output you should include *space* after {a} and *
24th May 2020, 5:51 PM
Lerninn
0
Lerninn K = 2 List = '1001101100011' result = re.findall(f'1{k}',List) I'm not getting output ? Can you help
1st May 2021, 7:16 AM
Levi
Levi - avatar