I have to replace any expression which look like:
"any_expression/2016.2
Can I do it with Regex?
String any_expressin
can contain any character and in any length
I have to replace any expression which look like:
"any_expression/2016.2
Can I do it with Regex?
String any_expressin
can contain any character and in any length
Of course you can, this should do it:
".*\/2016\.2
In Python:
str.replace(".*\/2016\.2", "whatYouWantInstead");
Answer to your question is "Yes".
If you want to know more about it then:
Regular expression matching your requirements is:
^".*(\/2016\.2)$
If it can be anywhere in text, just remove first and last character:
".*(\/2016\.2)
According to this question Python doesn't recognize regex for str.replace, then you need to use re.sub
. It should look like:
import re
line = re.sub(r"^\".*(\/2016\.2)$", r"replaced any expression\1", line)