I have a string in Python:string, It should be <\"changed\">changed to <\"a\">a nummber."
print Tt
'This is a <"string">string, It should be <"changed">changed to <"a">a nummber.'
<\" \">.
'This is a string, It should be changed to a nummber.'
Use regular expressions:
import re Tt = re.sub('<\".*?\">', '', Tt)
Note the
? after
*. It makes the expression non-greedy,
so it tries to match so few symbols between
<\" and
\"> as possible.
The Solution of James will work only in cases when the delimiting substrings
consist only from one character (
< and
>). In this case it is possible to use negations like
[^>]. If you want to remove a substring delimited with character sequences (e.g. with
begin and
end), you should use non-greedy regular expressions (i.e.
.*?).