-2

I have written code to search and replace string in make command as per user input

make language='english' id=234 version=V1 path='/bin'

In above code i searched version=V1 and replace version with version=V2

import re
strings = "make language='english' id=234 version=V1 path='/bin'"
search_pattern= re.search('version=(.*?)\s', strings)
old_str = search_pattern.group(1)
print test.replace(old_str, "V2")

Can anyone help me write above code in pythonic way or any other way to write above code

1
  • 5
    Why not strings.replace("V1", "V2")? Commented Nov 10, 2016 at 18:24

1 Answer 1

0

It's very easy if you use str.replace

String = "make language='english' id=234 version=V1 path='/bin'"
String = String.replace("version=V1", "version=V2")
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.