2

I want to remove only 1214" in "ilanlar\u0131 1214", "count"" or remove 2808" in "ilanlar\u0131 2808", "count"". How can I do by using regular expression in python?

I tried this code.

for line in fileinput.input('sektorler.json', inplace=True):

    print(line.replace("^\d+\," , ""))
1
  • just use \d+" with re.sub. str.replace doesn't support regex Commented Jun 7, 2015 at 14:17

1 Answer 1

2

You need to use re.sub which takes regex as first parameter. replace method must take a string as parameter.

re.sub(r'\d+"', "", strin)
Sign up to request clarification or add additional context in comments.

2 Comments

How can I write re.sub(r'\d+"', "", strin) in my for loop?
just replace your print function with print(re.sub(r'\d+"', "", line))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.