Search code examples
pythontwitter

Python re.sub group of number after word


How can I replace 'some n number(example 11 digit of any number) or some number with word(ex: any character like as12345678iu) to 'resi'?

I try with re.sub but didn't work, thank you... sorry I just learning python...

tweet = re.sub('(re{11}.\d[^\s]+)','resi',tweet)

Solution

  • Try pattern r'\b\w{11}\b'

    Ex:

    import re
    
    tweet = "any character like as123456789 or 12345678912"
    print( re.sub(r'\b\w{11}\b','resi', tweet) )  
    

    Output:

    any character like resi or resi