Reputation: 179
I am trying in python 3.7 to try to eliminate with Regex the sentence that begins with the character $. However, in doing so I also want to add the last comma of this amount.
My text is as follows:
Sr,(a). INMOB OSIK DE EXAM SPA,$5.910,CASTILLA N. 111 BL. B DPTO. 111,FECHA VENCIMIENTO
I need it to be as follows:
Sr,(a). INMOB OSIK DE EXAM SPA,CASTILLA N. 111 BL. B DPTO. 111,FECHA VENCIMIENTO
I have used this statement in python with library re
but I cannot include the last comma of the value.
pattern = r'([$.])\w+'
regex_response = re.sub(pattern, '',str(regex_response))
but the result of this sentence is:
Sr,(a). INMOB OSIK DE EXAM SPA,,CASTILLA N. 111 BL. B DPTO. 111,FECHA VENCIMIENTO
Any idea what the regex should look like to have that result?
Upvotes: 0
Views: 80
Reputation: 412
Obviously your code just works, all that is left is add the ',' character to the Pattern
pattern = r'([$.])\w+,?'
The above ',? matches zero or one occurence of the ',' character
Upvotes: 2