Search code examples
pythonpython-3.xpandasdataframepandas-datareader

I want to take user input in regular expression in pandas


Below is my code.

import pandas as pd

import re

text = "monotonous monumental  Hello friday monoclonal"

mon = input('please write first three letters which you want to find ? ')

Number = int(input('please write how many number you want to extract after three letters ? '))

pattern = re.compile(mon+'\w{Number}') #here in place of '{Number}' I want to use user input

match = pattern.findall(text)

print(match)

Solution

  • import pandas as pd
    import re
    text = "monotonous monumental Hello friday monoclonal"
    mon = input('please write first three letters which you want to find ? ')
    pattern = re.compile(mon+'\w{4}')#here in place of 'mon' I want to use user input
    match = pattern.findall(text)
    print(match)
    

    This should work.