python - Replacing strings in its entirity -
I want to change the words if it completely matches the string in Python.
Suppose,
st = 'lengthy take' I take all the words with the word "LE" & lt; =
Want to make the result
'Length & lt; = ' I tried to change it () and at re.sub () I want it
' & lt; = Ngth & lt; = ' Is there an inbuilt function for this operation?
Try something like this ... Import This regular expression is \ bLe \ b / Code> and & lt; = with all the matches. Expression means "le" where it is not surrounded by alphanumeric characters . Basically, where Le is surrounded by white space or punctuation marks. The Python is readable on the document, especially look at the \ b which matches the one word boundary.
Comments
Post a Comment