Replacing a leading text string with the same string in python
Question: I have the following tags in a xml file as

> &\hbox{(1b)}}$$ with the initial condition <2inline-formula>$x(0)$, where
> the subscript <3inline-formula>$p$ means 'plant'; <4inline-formula>$x_{p}(t)
> \in \Re^{n}$ is the state, <5inline-formula>$y_{p}(t)\in\Re^{q}$ is the
> output, and <6inline-formula>$u_{p}(t)\in\Re^{m}$ is the input; <7inline-
> formula>

I want to replace the inline-formulas which are all starting with numbers to
`<inline-formula>` but i am not able to give the condition to search for the
inline formula staring with numbers so any help on this.. Thanks in advance


Answer: You have to use regular expresions (`re` module) for detecting one or more
digits preceeding "inline-formula" (`\d+inline-formula`).

Like this for example:

    
    
    >>> import re
    >>> original = "&\hbox{(1b)}}$$ with the initial condition <2inline-formula>$x(0)$, where the subscript <3inline-formula>$p$ means 'plant’; <4inline-formula>$x_{p}(t) \in \Re^{n}$ is the state, <5inline-formula>$y_{p}(t)\in\Re^{q}$ is the output, and <6inline-formula>$u_{p}(t)\in\Re^{m}$ is the input; <7inline-formula>"
    >>> new = re.sub(r"<\d+inline-formula>", "<inline-formula>", original)
    >>> print new
    "&\\hbox{(1b)}}$$ with the initial condition <inline-formula>$x(0)$, where the subscript <inline-formula>$p$ means 'plant\xe2\x80\x99; <inline-formula>$x_{p}(t) \\in \\Re^{n}$ is the state, <inline-formula>$y_{p}(t)\\in\\Re^{q}$ is the output, and <inline-formula>$u_{p}(t)\\in\\Re^{m}$ is the input; <inline-formula>"
    >>> 
    

